A
Alex Fenton
Hi
I tried the code below- I thought
[a, b].sort
was always the same as
[a, b].sort { | x, y | x <=> y }
and don't understand why it's not in this case. The String subclass
method doesn't seem to get called in the no-arg version?
Thanks
alex
---
class Fragment < String
def <=>(other)
p "Called subclassed method"
= super
end
end
a = Fragment.new('abc')
x = Fragment.new('xyz')
p a < x
p x <= a
p [x, a].sort
p [x, a].sort { | i, j | i <=> j }
I tried the code below- I thought
[a, b].sort
was always the same as
[a, b].sort { | x, y | x <=> y }
and don't understand why it's not in this case. The String subclass
method doesn't seem to get called in the no-arg version?
Thanks
alex
---
class Fragment < String
def <=>(other)
p "Called subclassed method"
= super
end
end
a = Fragment.new('abc')
x = Fragment.new('xyz')
p a < x
p x <= a
p [x, a].sort
p [x, a].sort { | i, j | i <=> j }