Hash order bug?

G

Gary Wright

Right -- what I mean is, to_s is OK for strings and symbols but not
for integers.

I'm not following you:

irb(main):001:0> 186.to_s
=> "186"
irb(main):002:0>

Gary Wright
 
R

Robert Dober

Right -- what I mean is, to_s is OK for strings and symbols but not
for integers.
Right -- what I mean is, I am stupid :(. Should have understood your
post David, sorry.
Robert
 
G

Gary Wright

Yes but
2 < 10
while
2.to_s > 10.to_s


Ah, I was missing the context of 'sorted keys'.

It seems to me that the desire to have sorted keys and
to also have keys that are not comparable would be
an indication that something isn't quite right, either
the design is wrong or there are some bugs to be
removed.


Gary Wright
 
R

Robert Dober

Ah, I was missing the context of 'sorted keys'.

It seems to me that the desire to have sorted keys and
to also have keys that are not comparable would be
an indication that something isn't quite right, either
the design is wrong or there are some bugs to be
removed.

I agree with you and when it comes to keys being Strings and Symbols I
always try to convert them to symbols anyway (the uniqueness of keys
in a Hash and symbols just seem to fit).

However, not being able to sort arrays of Symbols automatically
bothers me, but this is maybe slightly OT after all.

Cheers
Robert
 
D

David A. Black

Hi --

Ah, I was missing the context of 'sorted keys'.

It seems to me that the desire to have sorted keys and
to also have keys that are not comparable would be
an indication that something isn't quite right, either
the design is wrong or there are some bugs to be
removed.

It's not that integers aren't comparable; it's that they're an example
of something you wouldn't want to filter through to_s prior to
comparing.


David

--
Upcoming Rails training by Ruby Power and Light:
Four-day Intro to Intermediate
May 8-11, 2007
Edison, NJ
http://www.rubypal.com/events/05082007
 
G

Gary Wright

It's not that integers aren't comparable; it's that they're an example
of something you wouldn't want to filter through to_s prior to
comparing.

I wasn't clear. My 'not comparable' comment was about a hash
with heterogeneous keys (integers, symbols, strings) or a hash
with non-comparable keys (symbols).

I agree with you that the ability to convert everything to a
string via #to_s or even to an integer via #object_id doesn't
necessarily result in a useful ordering.


Gary Wright
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top