Last active
December 10, 2015 19:29
-
-
Save iwadon/4482020 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Index: struct.c | |
| =================================================================== | |
| --- struct.c (revision 38743) | |
| +++ struct.c (working copy) | |
| @@ -283,9 +283,10 @@ | |
| /* | |
| * 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 @@ | |
| * 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
[ruby-core:51320]での指摘を受けて修正。