double 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +4 -3
- data/lib/double.rb +4 -7
- data/lib/double/version.rb +1 -1
- data/test/test_double.rb +2 -1
- metadata +2 -2
data/README.md
CHANGED
@@ -6,16 +6,17 @@
|
|
6
6
|
|
7
7
|
## Description
|
8
8
|
|
9
|
-
Something can be [familiar, yet foreign at once][uncanny]
|
9
|
+
Something can be [familiar, yet foreign at once][uncanny].
|
10
10
|
|
11
|
-
**Double** allows you to use a constant
|
11
|
+
**Double** allows you to use a constant before it is defined when
|
12
|
+
metaprogramming.
|
12
13
|
|
13
14
|
## Usage
|
14
15
|
|
15
16
|
```ruby
|
16
17
|
class Foo
|
17
18
|
extend Double
|
18
|
-
Bar
|
19
|
+
Bar # nothing raised
|
19
20
|
end
|
20
21
|
```
|
21
22
|
|
data/lib/double.rb
CHANGED
@@ -17,16 +17,13 @@ module Double
|
|
17
17
|
@name = name
|
18
18
|
end
|
19
19
|
|
20
|
-
def _
|
21
|
-
@_ ||= ::Kernel.const_get @name
|
22
|
-
end
|
23
|
-
|
24
20
|
def method_missing(mth, *args, &blk)
|
25
|
-
|
21
|
+
@klass ||= ::Kernel.eval "::#{@name}"
|
22
|
+
if @klass.respond_to? mth
|
26
23
|
(class << self; self; end).instance_eval do
|
27
|
-
def_delegator :@
|
24
|
+
def_delegator :@klass, mth
|
28
25
|
end
|
29
|
-
@
|
26
|
+
@klass.send mth, *args, &blk
|
30
27
|
else
|
31
28
|
super
|
32
29
|
end
|
data/lib/double/version.rb
CHANGED
data/test/test_double.rb
CHANGED
@@ -15,9 +15,10 @@ class TestDouble < Test::Unit::TestCase
|
|
15
15
|
|
16
16
|
Foo.extend Double
|
17
17
|
Foo.class_eval 'self.double = Bar'
|
18
|
-
assert_raise NameError do
|
18
|
+
e = assert_raise NameError do
|
19
19
|
Foo.double.baz
|
20
20
|
end
|
21
|
+
assert_nil e.message.match /Kernel::Bar/
|
21
22
|
|
22
23
|
Kernel.const_set :Bar, Module.new
|
23
24
|
assert_raise NoMethodError do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: double
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.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: 2012-06-
|
12
|
+
date: 2012-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|