From: Josh Cheek on 30 Dec 2009 07:21 [Note: parts of this message were removed to make it a legal post.] On Wed, Dec 30, 2009 at 6:08 AM, Fritz Trapper <ajfrenzel(a)web.de> wrote: > Thanks for your quick replies. > > I see, my scenario is somewhat more complicated, than I wrote in my > initial posting. The point is, that I want to pass an object and a > method. > > Something like this: > > def executer(obj, method) > f.method(1) > end > > class x > def test(x) > p x > end > end > > o = x.new > executer(o, test) > -- > Posted via http://www.ruby-forum.com/. > > def executer(obj, method) obj.send method , 1 end class X def test(x) p x end end o = X.new executer( o , :test )
From: Fritz Trapper on 30 Dec 2009 07:31 Thanks for your help. I got it and it works fine. Another question: Is there some ruby reference on the web, something like http://api.rubyonrails.org/ for example? -- Posted via http://www.ruby-forum.com/.
From: Jesús Gabriel y Galán on 30 Dec 2009 07:34 On Wed, Dec 30, 2009 at 1:31 PM, Fritz Trapper <ajfrenzel(a)web.de> wrote: > Thanks for your help. I got it and it works fine. > > Another question: > Is there some ruby reference on the web, something like > http://api.rubyonrails.org/ for example? http://ruby-doc.org/ Jesus.
From: Fritz Trapper on 30 Dec 2009 07:52 Jesús Gabriel y Galán wrote: > http://ruby-doc.org/ Thanks a lot. -- Posted via http://www.ruby-forum.com/.
From: Albert Schlef on 31 Dec 2009 00:58 Marnen Laibow-Koser wrote: > Fritz Trapper wrote: >> I see, my scenario is somewhat more complicated, than I wrote in my >> initial posting. The point is, that I want to pass an object and a >> method. >> >> Something like this: >> >> def executer(obj, method) >> f.method(1) >> end >> >> class x >> def test(x) >> p x >> end >> end >> >> o = x.new >> executer(o, test) Then you can use instance_method(), which is like method() except it returns an *unbound* method: def executer(obj, unbound_method) unbound_method.bind(obj).call(1234) end class X def test(x) p x end end o1 = X.new o2 = X.new o3 = X.new method = X.instance_method(:test) executer(o1, method) executer(o2, method) executer(o3, method) -- Posted via http://www.ruby-forum.com/.
First
|
Prev
|
Pages: 1 2 3 Prev: How to avoid \ escaping when using "= <<-EOF" ? Next: Why can't I use "or" here? |