Skip to content

Commit

Permalink
Add block support to Struct.new
Browse files Browse the repository at this point in the history
  • Loading branch information
meh committed Oct 22, 2013
1 parent 04aa48d commit 790b643
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion corelib/struct.rb
@@ -1,5 +1,5 @@
class Struct
def self.new(name = undefined, *args)
def self.new(name = undefined, *args, &block)
return super unless self == Struct

if name[0] == name[0].upcase
Expand All @@ -9,6 +9,8 @@ def self.new(name = undefined, *args)

Class.new(self) {
args.each { |arg| define_struct_attribute arg }

instance_eval(&block) if block
}
end
end
Expand Down

0 comments on commit 790b643

Please sign in to comment.