cin cin - 6 months ago 10
Ruby Question

Ruby & Nokogiri -- Sorting hashed numbers correctly

I have a question regarding the sorting of numbers in my hash.
I have stored a hash with items and values, based on a HTML webpage I scraped with Nokogiri.

Now, I managed to sort the hash by the values using the 'sort' method.
However, the numbers show up like this:

1.200
1
10
125
25
3

And I would love to return/sort my values like this:
1
3
10
25
125
1.200

Can someone help me out here? I've tried googling, but my search terms are so general (since I don't know what the correct way of sorting is called), that I couldn't find it.. Any help is welcome!

Thanks in advance!

Answer
▶ %w|1.200 1 10 125 25 3|.map { |e| e.gsub(/\D/, '').to_i }.sort
#⇒ [
#  [0] 1,
#  [2] 3,
#  [2] 10,
#  [3] 25,
#  [4] 125
#  [5] 1200,
# ]