Skip to content

Instantly share code, notes, and snippets.

@yangsu
Created January 28, 2013 03:52
Show Gist options
  • Save yangsu/4652885 to your computer and use it in GitHub Desktop.
Save yangsu/4652885 to your computer and use it in GitHub Desktop.
Ruby Enumerable
a = [5, 3, 4, 1]
a.sort # => [1, 3, 4, 5]
a.any? {|i| i > 6} # => false
a.any? {|i| i > 4} # => true
a.all? {|i| i > 4} # => false
a.all? {|i| i > 0} # => true
a.collect {|i| i * 2} # => [10, 6, 8, 2]
a.select {|i| i % 2 == 0 } # even => [4]
a.select {|i| i % 2 == 1 } # odd => [5, 3, 1]
a.max # => 5
a.member?(2) # => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment