diff --git a/book.xml b/book.xml index 97ffc15..b0e43e4 100644 --- a/book.xml +++ b/book.xml @@ -89,6 +89,7 @@ + diff --git a/src/ref/struct.xml b/src/ref/struct.xml new file mode 100644 index 0000000..71963d5 --- /dev/null +++ b/src/ref/struct.xml @@ -0,0 +1,40 @@ + + + + Struct + + Struct::ExampleStruct.newnamemember{ } Initialises and returns a new Class inheriting from Struct. It is named Struct::name, or is anonymous if name is omitted. An accessor method is defined for each member Symbol. If a block is given, it is evaluated in the context of the new Struct’s class. In the descriptions that follow, Struct::Example is a Class returned by this method. + + Struct::ExampleStruct::Example.newvalue Instantiates and returns an instance of the receiver. Each value is assigned to the corresponding member; an omitted value is nil. An ArgumentError is raised if more values are given than there are members. Aliased by Struct::Example[]. + + Struct::ExampleStruct::Example[]value Aliases Struct::Example.new. + + ArrayStruct::Example.members Returns the names of the receiver’s members as an Array of Symbols. + + true or falseStruct::Example#==object Returns true if object was generated by Struct.new and has the same number of members as the receiver, each of which have the same names and equal values according to #==; otherwise, false. + + ObjectStruct::Example#[]position + ObjectStruct::Example#[]name Returns the value of the given member, identified either by its Fixnum position or Symbol name. If there isn’t such a member, the first form raises an IndexError, and the second form raises a NameError. + + ObjectStruct::Example#[]=positionobject + ObjectStruct::Example#[]=nameobject Sets the value of the given member to object. A member is identified either by its Fixnum position or Symbol name. If there isn’t such a member, the first form raises an IndexError, and the second form raises a NameError. + + Struct::Example or EnumeratorStruct::Example#each{|value| } Yields the value of each member in turn, returning the receiver. If the block is omitted, an Enumerator is returned. + + Struct::Example or EnumeratorStruct::Example#each_pair{|member, value| } Yields the name of each Symbol member, in turn, along with its value, returning the receiver. If the block is omitted, an Enumerator is returned. + + IntegerStruct::Example#length Returns the number of members in the receiver. Aliased by Struct::Example#size. + + ArrayStruct::Example#members Returns the names of the receiver’s members as an Array of Symbols. + + IntegerStruct::Example#size Aliases Struct::Example#length. + + ArrayStruct::Example#to_a Returns the values of the receiver’s members. Aliased by Struct::Example#values. + + ArrayStruct::Example#values Aliases Struct::Example#to_a. + + ArrayStruct::Example#values_atposition Returns the values corresponding to the given members, which are specified as Fixnum positions or Ranges of the same. +