diff --git a/ChangeLog b/ChangeLog index db144d6f5f..47d87e5bb1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sat Jan 19 11:35:00 2013 Zachary Scott + + * struct.c (Struct.new): Document Struct.new with block + Patch by Hiroyuki Iwatsuki [Bug #7674] + Sat Jan 19 09:52:46 2013 Eric Hodel * doc/syntax/miscellaneous.rdoc: Added section on defined? diff --git a/struct.c b/struct.c index fc03130987..5e9f9a15a1 100644 --- a/struct.c +++ b/struct.c @@ -283,9 +283,10 @@ rb_struct_define(const char *name, ...) /* * call-seq: - * Struct.new( [aString] [, aSym]+> ) -> StructClass - * StructClass.new(arg, ...) -> obj - * StructClass[arg, ...] -> obj + * Struct.new( [aString] [, aSym]+> ) -> StructClass + * Struct.new( [aString] [, aSym]+> ) {|StructClass| block } -> StructClass + * StructClass.new(arg, ...) -> obj + * StructClass[arg, ...] -> obj * * Creates a new class, named by aString, containing accessor * methods for the given symbols. If the name aString is @@ -296,6 +297,16 @@ rb_struct_define(const char *name, ...) * letter. Assigning a structure class to a constant effectively gives * the class the name of the constant. * + * If a block is given, it will be evaluated in the context of + * StructClass, passing StructClass as a parameter. + * + * Customer = Struct.new(:name, :address) do + * def greeting + * "Hello #{name}!" + * end + * end + * Customer.new("Dave", "123 Main").greeting # => "Hello Dave!" + * * Struct::new returns a new Class object, * which can then be used to create specific instances of the new * structure. The number of actual parameters must be