![](http://www.gnu-darwin.org/hexley-gd-sm.png)
|
prev
-
up
-
next
-
index
-
Struct
-
The structure class. Struct.new creates the new subclass
of the Struct class and returns it. Each subclass has
access methods for the structure attributes.
-
SuperClass:
-
-
Object
-
Included Modules:
-
-
Enumerable
-
Class Methods:
-
-
new(name, member...)
-
Creates the new subclass of the Struct class, which is
named name and returns it. Each subclass has access
methods for the structure attributes. For example:
dog = Struct.new("Dog", :name, :age)
fred = dog.new("fred", 5)
fred.age=6
printf "name:%s age:%d", fred.name, fred.age
prints "name:fred age:6".
The structure name should start with captal letter, since
it is class constant name under the Struct class.
-
Class Methods for each structure:
-
-
new(value...)
-
-
[value...]
-
Creates a structure. The arguments are initial value of the
structure. The number of arguments must be same to the number of
attributes of the structure.
-
members
-
Returns an array of the struct member names.
-
Methods:
-
-
self[nth]
-
Returns the value of the nth attribute.
If nth is string, returns the value of the named attribute.
-
each
-
Iterates over each value of the struct member.
-
members
-
Returns an array of the struct member names.
-
values
-
to_a
-
Returns the attributes of the structure as an array. For example, the
following code prints your passwd entry.
print Etc.getpwuid.values.join(":"), "\n"
prev
-
up
-
next
-
index
matz@netlab.co.jp
|