sticky_blox 1.0.1 → 1.1.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.
- data/VERSION +1 -1
- data/lib/sticky_blox/behavior.rb +17 -3
- data/spec/sticky_blox_spec.rb +22 -14
- data/sticky_blox.gemspec +1 -1
- metadata +2 -2
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.0
|
|
1
|
+
1.1.0
|
data/lib/sticky_blox/behavior.rb
CHANGED
|
@@ -10,6 +10,10 @@ module StickyBlox
|
|
|
10
10
|
class << self; self; end
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
# Defines methods on the class identified by "binding"
|
|
14
|
+
# for each method in @stuck_methods that will call
|
|
15
|
+
# the block associated with that method name, passing
|
|
16
|
+
# any arguments that are defined at runtime
|
|
13
17
|
def stick_to( binding )
|
|
14
18
|
my_meta_class.instance_eval do
|
|
15
19
|
clz = self
|
|
@@ -49,10 +53,20 @@ module StickyBlox
|
|
|
49
53
|
|
|
50
54
|
def stick name, &block
|
|
51
55
|
my_meta_class.instance_eval do
|
|
52
|
-
@stuck_methods ||= []
|
|
53
|
-
@stuck_methods << name unless @stuck_methods.include?(name)
|
|
56
|
+
@stuck_methods ||= [] #{}
|
|
57
|
+
@stuck_methods << name unless @stuck_methods.include?(name) #[name] = block unless @stuck_methods.has_key?(name)
|
|
54
58
|
end
|
|
55
|
-
|
|
59
|
+
|
|
60
|
+
clz = self.class
|
|
61
|
+
clz.class_eval do
|
|
62
|
+
# define_method "#{name}=" do |arg|
|
|
63
|
+
# my_meta_class.instance_variable_get("@stuck_methods")[name] = block
|
|
64
|
+
# end
|
|
65
|
+
|
|
66
|
+
# def method_missing(meth, *args, &blk)
|
|
67
|
+
# raise "#{clz} doesn't respond to #{meth}"
|
|
68
|
+
# my_meta_class.instance_variable_get("@stuck_methods")[meth]
|
|
69
|
+
# end
|
|
56
70
|
define_method name do
|
|
57
71
|
block
|
|
58
72
|
end
|
data/spec/sticky_blox_spec.rb
CHANGED
|
@@ -48,20 +48,28 @@ describe "Class-based approaches" do
|
|
|
48
48
|
end
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
51
|
+
describe "Overriding stuck methods" do
|
|
52
|
+
before :all do
|
|
53
|
+
@original = Spearmint.chew
|
|
54
|
+
Spearmint.class_eval do
|
|
55
|
+
stick :chew do
|
|
56
|
+
self.upcase
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
after :all do
|
|
62
|
+
Spearmint.class_eval do
|
|
63
|
+
stick :chew, &@original
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it "should override the previously stuck method" do
|
|
68
|
+
Spearmint.stick_to String
|
|
69
|
+
s = 'a string'
|
|
70
|
+
s.chew.should == 'A STRING'
|
|
71
|
+
end
|
|
72
|
+
end
|
|
65
73
|
|
|
66
74
|
describe "Undefining stuck methods" do
|
|
67
75
|
it "should not throw an error if we try do unstick something that's never been stuck" do
|
data/sticky_blox.gemspec
CHANGED