L
Leslie Viljoen
Hi!
Is there a way that methods defined with define_method can take a block?
Here's my fighting module:
module Taikwando
def self.add_warrior(n)
define_method(n) do
puts "#{n} fights!"
yield
end
end
def fight(*names)
names.each do |n|
Taikwando.add_warrior(n)
end
end
end
include Taikwando
..when I require it, I can do this:
LocalJumpError: no block given
from ./kungfu.rb:102:in `neo'
from (irb):5
- the yield does not work. Any ideas?
Les
Is there a way that methods defined with define_method can take a block?
Here's my fighting module:
module Taikwando
def self.add_warrior(n)
define_method(n) do
puts "#{n} fights!"
yield
end
end
def fight(*names)
names.each do |n|
Taikwando.add_warrior(n)
end
end
end
include Taikwando
..when I require it, I can do this:
neo fights!fight "morpheus", "neo" => ["morpheus", "neo"]
neo do ?> puts "karate chop!"
end
LocalJumpError: no block given
from ./kungfu.rb:102:in `neo'
from (irb):5
- the yield does not work. Any ideas?
Les