From: Matthew Kerwin Date: 2012-05-19T13:05:07+09:00 Subject: Re: Methods as arguments? Just to make sure my head's on straight, the method is still bound to its original object, right? Any @instancevars in there will still refer to the right instance? On 19 May 2012 11:28, Robinson Risquez wrote: > Bartosz Dziewoński wrote in post #1061310: >> You would have to implement def aaa a little differently. >> >> >> If you want to call it as aaa('hello', :world): (note: this is >> generally a bad idea) >> >> def aaa(string, method) >>   print string >>   send method >> end >> >> Note the "send" – it call the method whose name is given as argument >> on "self"; in this case (with toplevel methods) it will be an implicit >> toplevel object. (If either of your methods belonged to some class, >> this would stop working – that's why it's a bad idea.) >> >> >> If you want to call it as aaa('hello', method(:world)): >> >>  def aaa(string, method) >>   print string >>   method.call >> end > > Thanks!, now the method world is invoked exactly as I wanted, in the aaa > method only. With either of two ways (send or call) works perfectly!. > Although I prefer to pass the method as an object and then invoke with > call. > > -- > Posted via http://www.ruby-forum.com/. --   Matthew Kerwin, B.Sc (CompSci) (Hons)   http://matthew.kerwin.net.au/   ABN: 59-013-727-651   "You'll never find a programming language that frees   you from the burden of clarifying your ideas." - xkcd