Skip to content

Instantly share code, notes, and snippets.

@bascht
Created April 27, 2011 08:37
Show Gist options
  • Save bascht/943934 to your computer and use it in GitHub Desktop.
Save bascht/943934 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
class SortMe
attr :foo
attr :bar
def initialize(foo, bar)
@foo = foo
@bar = bar
end
end
a = SortMe.new("eins", true)
b = SortMe.new("zwei", false)
c = SortMe.new("zwei", true)
d = SortMe.new("vier", true)
list = [a, b, c, d]
list.sort_by{ |f| [f.foo, f.bar == true ? 1 : 0] }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment