lib/enumeration.rb in enumeration-1.0.0 vs lib/enumeration.rb in enumeration-1.1.0

- old
+ new

@@ -9,12 +9,13 @@ c = Collection.new(map_or_list) # define an anonymous Module to extend on # defining a class level map reader class_methods = Module.new do - define_method(name) {|k| class_variable_get("@@#{name}")[k]} if c.map? + define_method(name.to_s+'_collection') { c.data } define_method(name.to_s+'_set') { c.set } + define_method(name) {|k| class_variable_get("@@#{name}")[k]} if c.map? end # set a class variable to store the enum map (used by above reader) # extend the anonymous module to get tne above class # level reader for the map @@ -28,11 +29,15 @@ c = self.class.send(:class_variable_get, "@@#{name}") instance_variable_set("@#{name}", c[value]) end # instance reader for the enum value - define_method(name) do - instance_variable_get("@#{name}") + define_method(name) { instance_variable_get("@#{name}") } + + # instance reader for the enum key + define_method(name.to_s+'_key') do + c = self.class.send(:class_variable_get, "@@#{name}") + c.key(instance_variable_get("@#{name}")) end end end class << self \ No newline at end of file