Skip to content
Browse files

Define methods passed in via options on the singleton class; otherwis…

…e, they will not take precedence over methods defined on the version module
  • Loading branch information...
1 parent 0e42826 commit 20c39ad9290e2481e950fecdbdb1db6ff04545e8 @alindeman alindeman committed
Showing with 7 additions and 2 deletions.
  1. +4 −2 lib/decor.rb
  2. +3 −0 spec/models/resource.rb
View
6 lib/decor.rb
@@ -206,11 +206,13 @@ def for(version, options = {})
# Options can override specific methods
options = { :version => version }.merge(options)
+
+ singleton_class = class << self; self; end;
options.each do |option, value_or_proc|
if value_or_proc.is_a?(Proc) or value_or_proc.is_a?(Method)
- self.class.send(:define_method, option, value_or_proc)
+ singleton_class.send(:define_method, option, value_or_proc)
else
- self.class.send(:define_method, option) { value_or_proc }
+ singleton_class.send(:define_method, option) { value_or_proc }
end
end
View
3 spec/models/resource.rb
@@ -32,6 +32,9 @@ def name
def computed
nil
end
+ def foo
+ "foo in v3"
+ end
end
end

0 comments on commit 20c39ad

Please sign in to comment.
Something went wrong with that request. Please try again.