Module: ClassyEnum::SuperClassMethods

Defined in:
lib/classy_enum.rb

Instance Method Summary collapse

Instance Method Details

#allObject



33
34
35
# File 'lib/classy_enum.rb', line 33

def all
  self::OPTIONS.map {|e| self.new(e) }
end

#all_with_nameObject

Uses the name field for select options



38
39
40
# File 'lib/classy_enum.rb', line 38

def all_with_name
  self.all.map {|e| [e.name, e.to_s] }
end

#find(option) ⇒ Object

Alias of new



47
48
49
# File 'lib/classy_enum.rb', line 47

def find(option)
  new(option)
end

#new(option) ⇒ Object



29
30
31
# File 'lib/classy_enum.rb', line 29

def new(option)
  self::OPTION_HASH[option] || TypeError.new("Valid #{self} options are #{self.valid_options}")
end

#valid_optionsObject



42
43
44
# File 'lib/classy_enum.rb', line 42

def valid_options
  self::OPTIONS.map(&:to_s).join(', ')
end