From: andrew Date: 2007-03-18T16:55:07+09:00 Subject: Re: accessing methods from the blocks caller Taking a better look at my pickaxe book, it seems as though this is simply a scoping issue that doesn't really have a solution. I have a workaround, but was curious to know if there was a "proper" way to accomplish what I was looking for. Thanks, Andrew "andrew" wrote in message news:w44Lh.32606$zU1.24952@pd7urf1no... > 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 >