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

View: New views
5 Messages — Rating Filter:   Alert me  

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

by Tony Arcieri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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)

--
Tony Arcieri
medioh.com

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

by Tony Arcieri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Mar 29, 2008 at 12:08 PM, Tony Arcieri <tony@...> wrote:

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

--
Tony Arcieri
medioh.com

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

by Robert Dober :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sat, Mar 29, 2008 at 7:08 PM, Tony Arcieri <tony@...> wrote:

> 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)
>
>  --
>  Tony Arcieri
>  medioh.com
>

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
--
http://ruby-smalltalk.blogspot.com/

---
Whereof one cannot speak, thereof one must be silent.
Ludwig Wittgenstein


Parent Message unknown Re: What's going on here? (weird Ruby 1.9 incompatibility)

by Yukihiro Matsumoto :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

In message "Re: What's going on here? (weird Ruby 1.9 incompatibility)"
    on Sun, 30 Mar 2008 22:38:37 +0900, ts <decoux@...> writes:

|Tony Arcieri wrote:
|> Is this a bug?
|
| Yes, can you submit it ?

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

                                                        matz.


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

by Tony Arcieri :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Mon, Mar 31, 2008 at 12:28 AM, Yukihiro Matsumoto <matz@...>
wrote:

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

Excellent, thank you!

--
Tony Arcieri
medioh.com