Class: Kernel::Enum

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/cenum.rb,
lib/version.rb

Constant Summary collapse

VERSION =
"0.1"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Enum

Returns a new instance of Enum.



13
14
15
# File 'lib/cenum.rb', line 13

def initialize(name)
  @value = self.class[name]
end

Class Method Details

.[](name) ⇒ Object



9
10
11
# File 'lib/cenum.rb', line 9

def self.[](name)
  const_get(constant_name(name))
end

.constant_name(name) ⇒ Object



5
6
7
# File 'lib/cenum.rb', line 5

def self.constant_name(name)
  name.to_s.upcase
end

Instance Method Details

#<=>(other) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/cenum.rb', line 17

def <=>(other)
  case other
  when Enum
    @value <=> other.__value__
  when String, Symbol
    @value <=> self.class[other]
  else
    @value <=> other
  end
end