Class: Ice::Identity

Inherits:
Object
  • Object
show all
Includes:
Inspect_mixin
Defined in:
lib/Ice.rb,
lib/Ice/Identity.rb

Overview

Reopen Identity to add the <=> method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspect_mixin

#inspect

Constructor Details

#initialize(name = '', category = '') ⇒ Identity

Returns a new instance of Identity.



24
25
26
27
# File 'lib/Ice/Identity.rb', line 24

def initialize(name='', category='')
    @name = name
    @category = category
end

Instance Attribute Details

#categoryObject

Returns the value of attribute category.



47
48
49
# File 'lib/Ice/Identity.rb', line 47

def category
  @category
end

#nameObject

Returns the value of attribute name.



47
48
49
# File 'lib/Ice/Identity.rb', line 47

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object



271
272
273
274
275
276
277
278
# File 'lib/Ice.rb', line 271

def <=>(other)
    n = self.name <=> other.name
    if n == 0
        return self.category <=> other.category
    else
        return n
    end
end

#==(other) ⇒ Object



36
37
38
39
40
41
# File 'lib/Ice/Identity.rb', line 36

def ==(other)
    return false if !other.is_a? ::Ice::Identity or
        @name != other.name or
        @category != other.category
    true
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/Ice/Identity.rb', line 43

def eql?(other)
    return other.class == self.class && other == self
end

#hashObject



29
30
31
32
33
34
# File 'lib/Ice/Identity.rb', line 29

def hash
    _h = 0
    _h = 5 * _h + @name.hash
    _h = 5 * _h + @category.hash
    _h % 0x7fffffff
end