named_value_class 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/named_value_class.rb +16 -0
- metadata +1 -1
data/lib/named_value_class.rb
CHANGED
@@ -36,8 +36,18 @@ def NamedValueClass(klass_name,superclass, &block)
|
|
36
36
|
def self.#{@name}()
|
37
37
|
#{name_error_name}
|
38
38
|
end
|
39
|
+
def #{@name}()
|
40
|
+
#{name_error_name}
|
41
|
+
end
|
39
42
|
EVAL
|
40
43
|
end
|
44
|
+
|
45
|
+
this = self
|
46
|
+
self.class.singleton_class.instance_eval do
|
47
|
+
@mapping ||= {}
|
48
|
+
@mapping[value] = this
|
49
|
+
end
|
50
|
+
|
41
51
|
named_values_collection << self
|
42
52
|
end
|
43
53
|
|
@@ -57,6 +67,12 @@ def NamedValueClass(klass_name,superclass, &block)
|
|
57
67
|
method_missing :inspect
|
58
68
|
end
|
59
69
|
|
70
|
+
def self.[](value)
|
71
|
+
singleton_class.instance_eval do
|
72
|
+
@mapping[value]
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
60
76
|
class_eval(&block) if block
|
61
77
|
end
|
62
78
|
|