sticky_blox 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.1
1
+ 1.1.0
@@ -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
- self.class.class_eval do
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
@@ -48,20 +48,28 @@ describe "Class-based approaches" do
48
48
  end
49
49
  end
50
50
 
51
- # describe "Overriding stuck methods" do
52
- # class NewSpearmint
53
- # include StickyBlox
54
- # stick :chew do
55
- # self.upcase
56
- # end
57
- # end
58
- #
59
- # it "should override the previously stuck method" do
60
- # NewSpearmint.stick_to String
61
- # s = 'a string'
62
- # s.chew.should == 'GNIRTS A'
63
- # end
64
- # end
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sticky_blox}
8
- s.version = "1.0.1"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jason Rogers"]
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 0
8
7
  - 1
9
- version: 1.0.1
8
+ - 0
9
+ version: 1.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jason Rogers