From: Gregory Marton Date: 2008-02-24T22:46:14+09:00 Subject: Re: passing method references in python & ruby What bugs me about ruby is that I can't do this def add_one(n) n + 1 end [3,6,8].map(add_one) => [4,7,9] I can't even do it more explicitly, because map won't take anything other than a block: irb(main):001:0> class A; def A.addone(x); x + 1; end; end => nil irb(main):002:0> A.method(:addone) => # irb(main):003:0> [3,6,8].map{|x| x + 1} => [4, 7, 9] irb(main):004:0> [3,6,8].map(A.method(:addone)) ArgumentError: wrong number of arguments (1 for 0) from (irb):4:in `map' from (irb):4 irb(main):005:0> [3,6,8].map(Proc.new{|x| A.method(:addone).call(x)}) ArgumentError: wrong number of arguments (1 for 0) from (irb):5:in `map' from (irb):5 irb(main):006:0> [3,6,8].map Proc.new{|x| A.method(:addone).call(x)} ArgumentError: wrong number of arguments (1 for 0) from (irb):6:in `map' from (irb):6 Any of these would be defeating the purpose of brevity anyway. The best I can do is to make a block that calls the proc I want: irb(main):007:0> [3,6,8].map{|x| A.method(:addone).call(x)} => [4, 7, 9] or more simply: irb(main):008:0> [3,6,8].map{|x| A.addone(x)} => [4, 7, 9] this seems a waste of keystrokes, a cognitive indirection, and probably even a few processor cycles. Is there a way? Grem -- Posted via http://www.ruby-forum.com/.