Class: Mjai::Mentsu

Inherits:
Object
  • Object
show all
Extended by:
WithFields
Includes:
Comparable
Defined in:
lib/mjai/mentsu.rb

Instance Attribute Summary collapse

Attributes included from WithFields

#field_names

Instance Method Summary collapse

Methods included from WithFields

define_fields

Constructor Details

#initialize(fields) ⇒ Mentsu

Returns a new instance of Mentsu.



15
16
17
# File 'lib/mjai/mentsu.rb', line 15

def initialize(fields)
  @fields = fields
end

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



19
20
21
# File 'lib/mjai/mentsu.rb', line 19

def fields
  @fields
end

Instance Method Details

#<=>(other) ⇒ Object



35
36
37
38
39
40
41
42
# File 'lib/mjai/mentsu.rb', line 35

def <=>(other)
  if self.class == other.class
    return Mentsu.field_names.map(){ |s| @fields[s] } <=>
        Mentsu.field_names.map(){ |s| other.fields[s] }
  else
    raise(ArgumentError, "invalid comparison")
  end
end

#==(other) ⇒ Object Also known as: eql?



25
26
27
# File 'lib/mjai/mentsu.rb', line 25

def ==(other)
  return self.class == other.class && @fields == other.fields
end

#hashObject



31
32
33
# File 'lib/mjai/mentsu.rb', line 31

def hash()
  return @fields.hash()
end

#inspectObject



21
22
23
# File 'lib/mjai/mentsu.rb', line 21

def inspect
  return "\#<%p %p>" % [self.class, @fields]
end