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.
Object
Enumerable
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:
prints "name:fred age:6".dog = Struct.new("Dog", :name, :age) fred = dog.new("fred", 5) fred.age=6 printf "name:%s age:%d", fred.name, fred.age
The structure name should start with captal letter, since
it is class constant name under the Struct
class.
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.
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"