Skip to content

Instantly share code, notes, and snippets.

@johnivanoff
Created September 28, 2017 15:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnivanoff/223fd9042f3d8a6b0b91cafd7d776c92 to your computer and use it in GitHub Desktop.
Save johnivanoff/223fd9042f3d8a6b0b91cafd7d776c92 to your computer and use it in GitHub Desktop.
placeholderA = []
placeholderB = []
fh.each do |key, value|
case key
when "sortdescending"
placeholderA << "a['#{value}']"
placeholderB << "b['#{value}']"
when "sortascending"
placeholderA << "b['#{value}']"
placeholderB << "a['#{value}']"
else
next
end
arr.sort { |a, b| [placeholderA] <=> [placeholderB] }
@johnivanoff
Copy link
Author

The problem is I get.
arr.sort { |a, b| ["a['price'], a['name']"] <=> ["b['price'], b['name']"] }
and not
arr.sort { |a, b| [a['price'], a['name']] <=> [b['price'], b['name']] }
How do I make not string?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment