Redefining hat operator for Proc

Hello,

I am developing a gem where I need to redefine the <=> operator for
Proc. This operator shows up in the methods list when I print the
output of methods call but I don’t see it in the list of private or
protected methods.

I know in Ruby 1.9 === operator has been redefined, but I am not able
to confirm that <=> is currently implemented in Ruby 1.9. I don’t want
to over-ride the hat operator if it is already implemented for Proc.
Could someone please give me some pointers?

TIA.
Bala

bparanj:

I am developing a gem where I need to redefine the <=> operator for
Proc. This operator shows up in the methods list when I print the
output of methods call but I don’t see it in the list of private or
protected methods.

puts RUBY_DESCRIPTION
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
=> nil

Proc.instance_methods.include? :<=>
=> false

Where do you see it?

Also,

a = Proc.new {}
=> #Proc:0x000000028d37e0@:6(irb)

b = Proc.new {}
=> #Proc:0x000000028c8a30@:7(irb)

a <=> b
NoMethodError: undefined method <=>' for #<Proc:0x000000028d37e0@(irb):6> from (irb):8 from /home/shot/.rvm/ruby-1.9.1-p243/bin/irb:12:in

— Shot

On 09/24/2009 10:47 PM, bparanj wrote:

Could someone please give me some pointers?
If you do Proc.instance_method(:<=>), what do you get? If nil, then
it’s not overridden.

Cheers

robert

If you do Proc.instance_method(:<=>), what do you get? If nil, then
it’s not overridden.

Cheers

    robert

irb(main):005:0> p = Proc.instance_method(:<=>)
NameError: undefined method <=>' for classProc’
from (irb):5:in instance_method' from (irb):5 from /usr/local/bin/irb:12:in

Looks like it is safe to redefine it. Thanks.

Hi –

On Fri, 25 Sep 2009, bparanj wrote:

NameError: undefined method <=>' for classProc’
from (irb):5:in instance_method' from (irb):5 from /usr/local/bin/irb:12:in

Looks like it is safe to redefine it. Thanks.

You just have to hope that no one else comes to the same conclusion
:slight_smile:

David