Maybe IRB Bug?

Hi gurus and nubys,

I just had this messsage:

a.sort_by &.method(:size)

ArgumentError: wrong number of arguments(1 for 0)
        from c:/Programmi/Ruby/lib/ruby/1.8/irb/workspace.rb:81:in
`eval'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb/workspace.rb:81:in
`evaluate'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb/context.rb:198:in
`evaluate'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:148:in `eval_input'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:145:in
`signal_status'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:145:in `eval_input'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:144:in
`each_top_level_statem
ent'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb/ruby-lex.rb:220:in
`loop'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb/ruby-lex.rb:248:in
`each_top_lev
el_statement'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb/ruby-lex.rb:219:in
`catch'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb/ruby-lex.rb:219:in
`each_top_lev
el_statement'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:144:in `eval_input'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:70:in `start'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:69:in `catch'
        from c:/Programmi/Ruby/lib/ruby/1.8/irb.rb:69:in `start'
        from c:/Programmi/Ruby/bin/irb:13
Maybe IRB bug!!

if you'r going to ask what the hell I'm doing, I was looking if I
could use an UnboundMethod as a block, I should have wrote:

a.sort_by &(Array.instance_method(:size))

TypeError: wrong argument type UnboundMethod (expected Proc)
        from (irb):19

wich does not work anyway :slight_smile:

Florian Groß (flgr) thought of using #to_proc some time ago, something
like:

batsman@tux-chan:/tmp$ cat dfgdfgw4e5t6dsegb.rb

class Symbol
    def to_proc
        lambda{|x| x.method(self).call }
    end
end

a = %w[sdf dsfsdferrt4we dsfdfg dfg dfgdf gdf gdf gdfg]
p a
p a.sort_by(&:size)
batsman@tux-chan:/tmp$ ruby dfgdfgw4e5t6dsegb.rb
["sdf", "dsfsdferrt4we", "dsfdfg", "dfg", "dfgdf", "gdf", "gdf", "gdfg"]
["sdf", "gdf", "gdf", "dfg", "gdfg", "dfgdf", "dsfdfg", "dsfsdferrt4we"]

···

On Mon, Jun 28, 2004 at 06:52:57PM +0900, gabriele renzi wrote:

>> a.sort_by &(Array.instance_method(:size))
TypeError: wrong argument type UnboundMethod (expected Proc)

--
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

<Skyhook> Where is 'bavaria' proper? I thought it was austria.
  -- Seen on #Linux

yuk, thanks, I remember the trick.
But I was more in the mood of providing a method like this:
ary.sort_by &getter(:size)

This has the advantage that #getter could accept some parameters and
return a more refined proc. Note that this does not actually save
typing :slight_smile:

But to say the truth, I just dislike typing argument in blocks two
times, like
do |x| x.foo end

I think I'll be happy with something like a 'default parameter' (say,
grovy has 'it' for this). Not that important, anyway.

···

il Mon, 28 Jun 2004 19:03:16 +0900, Mauricio Fernández <batsman.geo@yahoo.com> ha scritto::

On Mon, Jun 28, 2004 at 06:52:57PM +0900, gabriele renzi wrote:

>> a.sort_by &(Array.instance_method(:size))
TypeError: wrong argument type UnboundMethod (expected Proc)

Florian Groß (flgr) thought of using #to_proc some time ago, something
like: