named_value_class 0.4.0 → 0.4.1

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 +24 -16
  2. metadata +2 -2
@@ -25,21 +25,25 @@ def NamedValueClass(klass_name,superclass, &block)
25
25
  named_values_module.const_set(@name, self)
26
26
  rescue NameError
27
27
  name_error_name = "NameError_#{@name}"
28
- self.class.const_set(name_error_name, self)
29
- named_values_module.const_set(name_error_name, self)
30
- self.class.class_eval <<-EVAL
31
- def self.#{@name}()
32
- #{name_error_name}
33
- end
34
- EVAL
35
- named_values_module.module_eval <<-EVAL
36
- def self.#{@name}()
37
- #{name_error_name}
38
- end
39
- def #{@name}()
40
- #{name_error_name}
41
- end
42
- EVAL
28
+ begin
29
+ self.class.const_get(name_error_name)
30
+ rescue NameError
31
+ self.class.const_set(name_error_name, self)
32
+ named_values_module.const_set(name_error_name, self)
33
+ self.class.class_eval <<-EVAL
34
+ def self.#{@name}()
35
+ #{name_error_name}
36
+ end
37
+ EVAL
38
+ named_values_module.module_eval <<-EVAL
39
+ def self.#{@name}()
40
+ #{name_error_name}
41
+ end
42
+ def #{@name}()
43
+ #{name_error_name}
44
+ end
45
+ EVAL
46
+ end
43
47
  end
44
48
 
45
49
  this = self
@@ -83,7 +87,11 @@ def NamedValueClass(klass_name,superclass, &block)
83
87
  EVAL
84
88
 
85
89
  define_singleton_method klass_name do |name,value,attrs={}|
86
- klass.const_get(name) rescue klass.new(name,value,attrs)
90
+ begin
91
+ klass.const_get(name) || klass.const_get("NameError_#{name}")
92
+ rescue NameError #=> e
93
+ klass.new(name,value,attrs)
94
+ end
87
95
  end
88
96
 
89
97
  klass
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.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-16 00:00:00.000000000Z
12
+ date: 2011-11-17 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description: Quickly add class delegate constants which output their names, not their
15
15
  values. This may be desirable for some DSLs.