Class: EnumAccessor::ClassMethods::Definition
- Inherits:
-
Object
- Object
- EnumAccessor::ClassMethods::Definition
- Defined in:
- lib/enum_accessor.rb
Instance Attribute Summary collapse
-
#dict ⇒ Object
Returns the value of attribute dict.
Instance Method Summary collapse
- #human_dict ⇒ Object
-
#initialize(column, keys, klass) ⇒ Definition
constructor
A new instance of Definition.
Constructor Details
#initialize(column, keys, klass) ⇒ Definition
Returns a new instance of Definition.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/enum_accessor.rb', line 85 def initialize(column, keys, klass) dict = case keys when Array Hash[keys.map.with_index{|i,index| [i, index] }] when Hash keys else raise ArgumentError.new('enum_accessor takes Array or Hash as the second argument') end @column = column @klass = klass @dict = dict.with_indifferent_access.freeze end |
Instance Attribute Details
#dict ⇒ Object
Returns the value of attribute dict.
83 84 85 |
# File 'lib/enum_accessor.rb', line 83 def dict @dict end |
Instance Method Details
#human_dict ⇒ Object
100 101 102 103 |
# File 'lib/enum_accessor.rb', line 100 def human_dict # Don't memoize - I18n.locale can change Hash[@dict.keys.map{|key| [key, @klass.send("human_#{@column}", key)] }].with_indifferent_access end |