Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Znav
nextRuby Mapping for Sequences
prevRuby Mapping for Enumerations

A Slice structure maps to a Ruby class with the same name. For each Slice data member, the Ruby class contains a corresponding instance variable as well as accessors to read and write its value. For example, here is our Employee structure once more:

Wiki Markup
{zcode:slice}
struct Employee {
    long number;
    string firstName;
    string lastName;
};
{zcode}

The Ruby mapping generates the following definition for this structure:

Wiki Markup
{zcode:rb}
class Employee
    def initialize(number=0, firstName='', lastName='')
        @number = number
        @firstName = firstName
        @lastName = lastName
    end

    def hash
        # ...
    end

    def ==
        # ...
    end

    def inspect
        # ...
    end

    attr_accessor :number, :firstName, :lastName
end
{zcode}

The constructor initializes each of the instance variables to a default value appropriate for its type. You can also declare different default values for members of primitive and enumerated types.

The compiler generates a definition for the hash method, which allows instances to be used as keys in a hash collection. The hash method returns a hash value for the structure based on the value of its data members.

The == method returns true if all members of two structures are (recursively) equal.

The inspect method returns a string representation of the structure.

Ztop
See Also
Zret
Znav
nextRuby Mapping for Sequences
prevRuby Mapping for Enumerations