A
andrew
Hello,
Sorry if this has been asked many times before, but I'm having a hard time
finding the right keywords to search for this one.
Here's my question... if I have a method that accepts a block and I want to
call a method of the class I'm in, in that block, how do I do it? See the
comment below in the example. Should make that sentence a bit clearer.
class Test
def method1
end
def method2
accept_block do # accept_block is not part of the Test class
...
method1 # I want to call method1 from the class I'm in, but
I'm getting undefined method for method1
...
end
end
end
I understand why I would be getting this error, but I don't know how to fix
it. Is there a way to access the caller in the block in order to access the
method of it? Kernel.caller is the closest I found, but it's not what I
want.
I hope this makes some sense. The example is a bit contrived, but hopefully
I get the point across.
Thanks,
Andrew
Sorry if this has been asked many times before, but I'm having a hard time
finding the right keywords to search for this one.
Here's my question... if I have a method that accepts a block and I want to
call a method of the class I'm in, in that block, how do I do it? See the
comment below in the example. Should make that sentence a bit clearer.
class Test
def method1
end
def method2
accept_block do # accept_block is not part of the Test class
...
method1 # I want to call method1 from the class I'm in, but
I'm getting undefined method for method1
...
end
end
end
I understand why I would be getting this error, but I don't know how to fix
it. Is there a way to access the caller in the block in order to access the
method of it? Kernel.caller is the closest I found, but it's not what I
want.
I hope this makes some sense. The example is a bit contrived, but hopefully
I get the point across.
Thanks,
Andrew