Skip to content

Instantly share code, notes, and snippets.

@iwadon
Last active December 10, 2015 19:29
Show Gist options
  • Select an option

  • Save iwadon/4482020 to your computer and use it in GitHub Desktop.

Select an option

Save iwadon/4482020 to your computer and use it in GitHub Desktop.
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
@iwadon

iwadon commented Jan 8, 2013

Copy link
Copy Markdown
Author

[ruby-core:51320]での指摘を受けて修正。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment