invoking proc with instance_eval with arguments
Posted
by dorelal
on Stack Overflow
See other posts from Stack Overflow
or by dorelal
Published on 2010-05-03T15:39:08Z
Indexed on
2010/05/03
15:48 UTC
Read the original article
Hit count: 357
ruby
I know this works
proc = Proc.new do
puts self.hi + ' world'
end
class Usa
def hi
"Hello!"
end
end
Usa.new.instance_eval &proc
However I want to pass arguments to proc. So I tried this which does not work. Can anyone help me make following work.
proc = Proc.new do |greeting|
puts self.hi + gretting
end
class Usa
def hi
"Hello!"
end
end
Usa.new.instance_eval &proc, 'world' # does not work
Usa.new.instance_eval &proc('world') # does not work
© Stack Overflow or respective owner