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.
- data/lib/named_value_class.rb +24 -16
- metadata +2 -2
data/lib/named_value_class.rb
CHANGED
@@ -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
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
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
|
-
|
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.
|
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-
|
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.
|