Skip to content

Instantly share code, notes, and snippets.

@eam
Created August 30, 2012 18:34
Show Gist options
  • Save eam/3536925 to your computer and use it in GitHub Desktop.
Save eam/3536925 to your computer and use it in GitHub Desktop.
def sorted(enumerable)
enumerable.sort do |a, b|
if Hash === a && Hash === b
if a[:name] && b[:name]
a[:name] <=> b[:name]
else
sorted(a.keys).inspect <=> sorted(b.keys).inspect
end
elsif Symbol === a && Symbol === b
puts "DEBUG: symbol"
a.to_s <=> b.to_s
else
puts "DEBUG: a and b are: #{a.class} and #{b.class}"
a <=> b
puts "after compare"
end
end
end
a and b are: Array and Array
-:17:in `<=>': undefined method `<=>' for :type:Symbol (NoMethodError)
from -:17:in `sorted'
from -:5:in `sort'
from -:5:in `sorted'
from -:525
from -:522:in `each'
from -:522
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment