Skip to content

Instantly share code, notes, and snippets.

@dkubb
Created January 30, 2009 01:13
Show Gist options
  • Save dkubb/54872 to your computer and use it in GitHub Desktop.
Save dkubb/54872 to your computer and use it in GitHub Desktop.
# limit/offset using Enumerable#slice
collection[0, 20] # LIMIT 0, 20
collection[0..20] # LIMIT 0, 20
# ordering using Enumerable#sort_by (will not require ParseTree)
collection.sort_by { |o| o.name } # ORDER BY name
collection.sort_by { |o| -o.name } # ORDER BY name DESC
collection.sort_by { |o| [ -o.name, o.age ] } # ORDER BY name DESC, age
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment