From: Matthias Reitinger Date: 2009-03-20T11:39:56+09:00 Subject: Re: Passing a named function instead of a code block? Paul Jungwirth wrote: > I have a question about ruby's feature that when you call a method, you > can pass in a block of code after the last argument. Instead of writing > a code block, suppose I already have a def'd method that would work just > as well. Is there any way I can pass that in directly? For example, > suppose I have this code: > > #!/usr/bin/env ruby > > def fib(n) > a, b = 0, 1 > n.times do |i| > a, b = b, a+b > end > b > end > > c = [1, 2, 3, 4] > > puts c.collect {|i| fib i} puts c.collect(&method(:fib)) -Matthias -- Posted via http://www.ruby-forum.com/.