Module: Enumerations::Value

Included in:
Base
Defined in:
lib/enumerations/value.rb

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Comparison by symbol or object

Example:

Role.admin == :admin      => true
Role.admin == Role.admin  => true
Role.admin == :staff      => false
Role.admin == Role.staff  => false

TODO: test if case..when is working with this



29
30
31
32
33
34
35
# File 'lib/enumerations/value.rb', line 29

def ==(other)
  case other
  when String then other == to_s
  when Symbol then other == symbol
  else super
  end
end

#to_iObject



3
4
5
# File 'lib/enumerations/value.rb', line 3

def to_i
  _values.keys.index(symbol) + 1
end

#to_paramObject



11
12
13
# File 'lib/enumerations/value.rb', line 11

def to_param
  to_s
end

#to_sObject



7
8
9
# File 'lib/enumerations/value.rb', line 7

def to_s
  symbol.to_s
end

#to_symObject



15
16
17
# File 'lib/enumerations/value.rb', line 15

def to_sym
  symbol
end