What's going on here? (weird Ruby 1.9 incompatibility)

T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

class A
def a
'yay'
end
end

class B
def initialize(&meth)
class << self; self; end.__send__:)define_method, :b, &meth)
end
end

b = B.new &A.new.method:)a)
p b.b

Ruby 1.8 prints:
"yay"

Ruby 1.9 complains (on the p b.b line):
14:in `<main>': wrong number of arguments (1 for 0) (ArgumentError)
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

Ruby 1.8 prints:
"yay"

Ruby 1.9 complains (on the p b.b line):
14:in `<main>': wrong number of arguments (1 for 0) (ArgumentError)

I tried changing A to have the following definition:

class A
def a(*args)
args
end
end

Now:

Ruby 1.8:
[]

or if you call b.b(1,2,3):
[1,2,3]

Ruby 1.9:
[nil]

or if you call b.b(1,2,3):
[1]

Is this a bug?
 
R

Robert Dober

class A
def a
'yay'
end
end

class B
def initialize(&meth)
class << self; self; end.__send__:)define_method, :b, &meth)
end
end

b = B.new &A.new.method:)a)
p b.b

Ruby 1.8 prints:
"yay"

Ruby 1.9 complains (on the p b.b line):
14:in `<main>': wrong number of arguments (1 for 0) (ArgumentError)

I added the output of the arity of the methods, looks very much like a
bug to me, are you familiar with the Bug Reporting process?

<code>
ma = A.new.method:)a)
p ma.arity # --> 0
b = B.new( &ma )
mb = b.method:)b)
p mb.arity # --> 0

p b.b # bombs
</code>

Cheers
Robert
 
T

Tony Arcieri

[Note: parts of this message were removed to make it a legal post.]

You don't have to. I just fixed, and am going to commit soon between
EURUKO sessions.

Excellent, thank you!
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top