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.
Files changed (2) hide show
  1. data/lib/named_value_class.rb +16 -0
  2. metadata +1 -1
@@ -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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: named_value_class
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: