ruby-changes:26831
From: zzak <ko1@a...>
Date: Sat, 19 Jan 2013 11:38:18 +0900 (JST)
Subject: [ruby-changes:26831] zzak:r38883 (trunk): * struct.c (Struct.new): Document Struct.new with block
zzak 2013-01-19 11:37:01 +0900 (Sat, 19 Jan 2013) New Revision: 38883 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38883 Log: * struct.c (Struct.new): Document Struct.new with block Patch by Hiroyuki Iwatsuki [Bug #7674] Modified files: trunk/ChangeLog trunk/struct.c Index: ChangeLog =================================================================== --- ChangeLog (revision 38882) +++ ChangeLog (revision 38883) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jan 19 11:35:00 2013 Zachary Scott <zachary@z...> + + * struct.c (Struct.new): Document Struct.new with block + Patch by Hiroyuki Iwatsuki [Bug #7674] + Sat Jan 19 09:52:46 2013 Eric Hodel <drbrain@s...> * doc/syntax/miscellaneous.rdoc: Added section on defined? Index: struct.c =================================================================== --- struct.c (revision 38882) +++ struct.c (revision 38883) @@ -283,9 +283,10 @@ rb_struct_define(const char *name, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L283 /* * 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 <i>aString</i>, containing accessor * methods for the given symbols. If the name <i>aString</i> is @@ -296,6 +297,16 @@ rb_struct_define(const char *name, ...) https://github.com/ruby/ruby/blob/trunk/struct.c#L297 * 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 + * <i>StructClass</i>, passing <i>StructClass</i> as a parameter. + * + * Customer = Struct.new(:name, :address) do + * def greeting + * "Hello #{name}!" + * end + * end + * Customer.new("Dave", "123 Main").greeting # => "Hello Dave!" + * * <code>Struct::new</code> returns a new <code>Class</code> object, * which can then be used to create specific instances of the new * structure. The number of actual parameters must be -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/