Module: Enumerations::Value

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

Instance Method Summary collapse

Instance Method Details

#==(other) ⇒ Object

Comparison by id, symbol or object

Example:

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

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



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

def ==(other)
  case other
  when Fixnum then other == id
  when Symbol then other == symbol
  else super
  end
end

#to_iObject



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

def to_i
  id
end

#to_paramObject



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

def to_param
  id
end

#to_sObject



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

def to_s
  name
end

#to_symObject



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

def to_sym
  symbol
end