Module: Behavioral

Defined in:
lib/behavioral.rb,
lib/behavioral/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Instance Method Summary collapse

Instance Method Details

#with_behaviors(*mods) ⇒ Object



4
5
6
7
8
9
10
11
12
13
# File 'lib/behavioral.rb', line 4

def with_behaviors(*mods)
  Array(mods).each do |mod|
    mod.instance_methods.each do |meth|
      instance_exec(meth, mod.instance_method(meth)){|m, unbound_method|
        define_singleton_method m, unbound_method
      }
    end
  end
  self
end

#without_behaviors(*mods) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/behavioral.rb', line 15

def without_behaviors(*mods)
  Array(mods).each do |mod|
    mod.instance_methods.each do |meth|
      singleton_class.send(:remove_method, meth) if singleton_methods.include?(meth)
    end
  end
  self
end