dynamic_ruby 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/dynamic_ruby.rb +11 -2
- data/spec/dynamic_ruby_spec.rb +6 -2
- metadata +10 -10
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 99f0591b26941a755b24ca398414ee6afb59bae8
|
4
|
+
data.tar.gz: f50b2ad4e78c820f1dfdea9d3032c3c6f974c514
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: edcbae771eca3b9e13676cdff48a3d8ce8c1561a5ce26ac28bd8e20fb98af72ac1ecd106ded9b6f8d09fb7fc254e97fc599fde062fbdaed07de3219d67a74d75
|
7
|
+
data.tar.gz: 1c46897936aa9dd667f8f06d7afb73c09950d8e6a9b7483dd668e73e894df464871c757c2b071fed0ae4e0068a5de76a12163c24b9cf1ab4d7ba2682661569f9
|
data/lib/dynamic_ruby.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
|
+
class DynamicLookup
|
2
|
+
def [](name)
|
3
|
+
val = Thread.current[name]
|
4
|
+
val ? val : ("unbound_variable_" + name.to_s).to_sym
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
DYNAMIC_LOOKUP = DynamicLookup.new
|
9
|
+
|
1
10
|
def dynamic(bindings={}, &block)
|
2
11
|
if !block_given?
|
3
|
-
|
12
|
+
DYNAMIC_LOOKUP
|
4
13
|
else
|
5
14
|
defined = {}
|
6
15
|
bindings.each do |name, val|
|
@@ -16,7 +25,7 @@ def dynamic(bindings={}, &block)
|
|
16
25
|
if defined[name]
|
17
26
|
Thread.current[name] = defined[name]
|
18
27
|
else
|
19
|
-
Thread.current[name] =
|
28
|
+
Thread.current[name] = ("unbound_variable_" + name.to_s).to_sym
|
20
29
|
end
|
21
30
|
end
|
22
31
|
end
|
data/spec/dynamic_ruby_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe "dynamic scope" do
|
|
9
9
|
result = testfun.call
|
10
10
|
end
|
11
11
|
result.must_equal "john"
|
12
|
-
testfun.call.
|
12
|
+
testfun.call.must_equal :unbound_variable_name
|
13
13
|
end
|
14
14
|
|
15
15
|
it "should stack access to dynamically declare variables" do
|
@@ -52,6 +52,10 @@ describe "dynamic scope" do
|
|
52
52
|
rescue
|
53
53
|
end
|
54
54
|
result = dynamic[:name]
|
55
|
-
result.
|
55
|
+
result.must_equal :unbound_variable_name
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should be unbound variable when accessed before setting" do
|
59
|
+
dynamic[:setting].must_equal :unbound_variable_setting
|
56
60
|
end
|
57
61
|
end
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynamic_ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
5
|
-
prerelease:
|
4
|
+
version: 2.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Jürgen Bickert
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-
|
11
|
+
date: 2013-09-29 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description: A thin wrapper around ruby for easy use of dynamic scope in your rubies
|
15
14
|
email: juergenbickert@gmail.com
|
@@ -21,27 +20,28 @@ files:
|
|
21
20
|
- spec/dynamic_ruby_spec.rb
|
22
21
|
homepage: http://juergenbickert.de
|
23
22
|
licenses: []
|
23
|
+
metadata: {}
|
24
24
|
post_install_message:
|
25
25
|
rdoc_options: []
|
26
26
|
require_paths:
|
27
27
|
- lib
|
28
28
|
- lib
|
29
29
|
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
30
|
requirements:
|
32
|
-
- -
|
31
|
+
- - '>='
|
33
32
|
- !ruby/object:Gem::Version
|
34
33
|
version: '0'
|
35
34
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
36
|
-
none: false
|
37
35
|
requirements:
|
38
|
-
- -
|
36
|
+
- - '>='
|
39
37
|
- !ruby/object:Gem::Version
|
40
38
|
version: '0'
|
41
39
|
requirements: []
|
42
40
|
rubyforge_project:
|
43
|
-
rubygems_version: 1.
|
41
|
+
rubygems_version: 2.1.5
|
44
42
|
signing_key:
|
45
|
-
specification_version:
|
43
|
+
specification_version: 4
|
46
44
|
summary: A library which correctly implements dynamic scope for ruby.
|
47
|
-
test_files:
|
45
|
+
test_files:
|
46
|
+
- spec/dynamic_ruby_spec.rb
|
47
|
+
has_rdoc:
|