Maybe IRB Bug?

G

gabriele renzi

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
TypeError: wrong argument type UnboundMethod (expected Proc)
from (irb):19

wich does not work anyway :)
 
M

Mauricio Fernández

TypeError: wrong argument type UnboundMethod (expected Proc)

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"]



--
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
 
G

gabriele renzi

il Mon, 28 Jun 2004 19:03:16 +0900, Mauricio Fernández
Florian Groß (flgr) thought of using #to_proc some time ago, something
like:

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 :)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

:IRB Bug 1
Bug in IRB 3
problem with irb 2
Ruby 1.9 named arguments 5
Using fetch_fields in MySQL for Windows 2
Bug in irb? 0
Problem on an example from ruby-lang.org 1
Strange bug in irb1.9 7

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top