Module: Enumish

Extended by:
ActiveSupport::Concern
Defined in:
lib/enumish.rb,
lib/enumish/version.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

VERSION =
"0.9.2"

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_id, *args, &block) ⇒ Object

Allow calls such as object.friendly? or model.attitude.friendly?



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/enumish.rb', line 36

def method_missing(method_id, *args, &block)
  bare_method = if method_id.to_s.match(/\?$/) && args.empty? && block.nil?
    method_id.to_s.sub(/\?$/, "")
  end

  if bare_method && self.class.enum_ids.include?(bare_method)
    self.send(self.class.enum_id.to_s) == bare_method
  else
    super
  end
end

Instance Method Details

#to_sObject



48
49
50
# File 'lib/enumish.rb', line 48

def to_s
  self.send(self.class.enum_id).to_s
end

#to_symObject



52
53
54
# File 'lib/enumish.rb', line 52

def to_sym
  self.send(self.class.enum_id).to_sym
end