Class: Chickadee::NumericID

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/chickadee/vos/numeric_id.rb

Instance Method Summary collapse

Constructor Details

#initialize(id) ⇒ NumericID

Returns a new instance of NumericID.

Raises:

  • (ArgumentError)


5
6
7
8
# File 'lib/chickadee/vos/numeric_id.rb', line 5

def initialize(id)
  raise(ArgumentError, "invalid id: #{id}") unless id.is_a?(Integer) && id > 0
  @id = id
end

Instance Method Details

#<=>(other) ⇒ Object



14
15
16
# File 'lib/chickadee/vos/numeric_id.rb', line 14

def <=>(other)
  self.to_i <=> other.to_i
end

#==(other) ⇒ Object



18
19
20
# File 'lib/chickadee/vos/numeric_id.rb', line 18

def ==(other)
  self.class == other.class && self.hash == other.hash
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/chickadee/vos/numeric_id.rb', line 22

def eql?(other)
  self == other
end

#hashObject



26
27
28
# File 'lib/chickadee/vos/numeric_id.rb', line 26

def hash
  @id.hash
end

#to_iObject



10
11
12
# File 'lib/chickadee/vos/numeric_id.rb', line 10

def to_i
  @id
end