Christian van der Leeden wrote:
> How about
> hashTable.sort.keys[0,10].each { |key| puts "#{key} #{hashTable[key]} }
This isn't going to work because hashTable.sort does not return a hash.
The object returned does not have a keys method.
However, reversing the chaining will work, and should actually be more
efficient anyway:
Example:
hashTable.keys.sort[0,10].each { |key| puts "#{key} #{hashTable[key]} }
In this case you get the keys array from the hash and then sort the keys
and take the first 10 keys then finally iterate the 10 with each.
P.S. I'm guessing you're coming from a camelCase world. Which is okay I
live there too as I do Java in my day job. But, if you wish to follow
Ruby conventions your variable should be hash_table not hashTable.
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---