lib/behavioral.rb in behavioral-0.0.1 vs lib/behavioral.rb in behavioral-1.0.0
- old
+ new
@@ -1,20 +1,22 @@
require "behavioral/version"
module Behavioral
def with_behaviors(*mods)
- mods.each do |mod|
+ Array(mods).each do |mod|
mod.instance_methods.each do |meth|
- self.define_singleton_method(meth, mod.instance_method(meth))
+ instance_exec(meth, mod.instance_method(meth)){|m, unbound_method|
+ define_singleton_method m, unbound_method
+ }
end
end
self
end
def without_behaviors(*mods)
- mods.each do |mod|
+ Array(mods).each do |mod|
mod.instance_methods.each do |meth|
- self.singleton_class.send(:remove_method, meth)
+ singleton_class.send(:remove_method, meth) if singleton_methods.include?(meth)
end
end
self
end
end