Website hosting service by Active-Venture.com
 

 Back to Index

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

 

  

 

 

2002-2004 Active-Venture.com Website Hosting Service

 
Buy domain name at only $5.95/yr with comprehensive domain hosting services. Domain registration and domain search service from $5.95 Cheap domain name registration and domain transfer service
 

Disclaimer: This documentation is provided only for the benefits of our website hosting customers.
For authoritative source of the documentation, please refer to http://www.ruby-doc.org/docs/