cheat sheets.

$ cheat enumerable
Ruby Enumerable mixin:
all? {|obj| }    Returns true if EVERY obj returns true from block
any? {|obj| }    Returns true if ANY obj returns true from block
collect {|obj| } Alias for map
detect(ifnone=nil) {|obj| }  alias for find
each_cons(n) {}  Iterates over each array of n consecutive elements (overlap)
each_slice(n) {} Iterates over each slice of n elements (no overlap)
each_with_index {|obj, index| ... }
entries          Returns an Array of all objects, alias for to_a
enum_cons(n)     Returns Enumerable::Enumerator.new(self, :each_cons, n).
enum_slice(n)    Returns Enumerable::Enumerator.new(self, :each_slice, n).
enum_with_index  Returns Enumerable::Enumerator.new(self, :each_with_index).
find(ifnone=nil) {|obj| }  Returns first obj for which block is true
find_all {|obj|} Returns an Array of all objects for which block is true
grep(pattern) {} Returns an Array of / iterates over objects that === pattern
include?(obj)    True if any member == obj
inject(initial) {|mem, obj| } Runs block on each obj, with last result in mem
inject {|mem, obj| }          Like above but first element used for initial
map {|obj| }     Returns new array with results of running block on each element
max              Returns largest element; elements must be Comparable
max {|a,b| }     Returns largest element; block should return a <=> b
member?          Alias for include?
min              Like max but returns smallest
partition {|obj|} Returns [[objects block was true], [objects block was false]]
reject {|obj| }  Returns array of elements for which block was false
select           Alias for find_all
sort		 Returns array of elements sorted; elements must be Comparable
sort {|a,b| }	 Returns elements sorted, block should return a <=> b
sort_by {|obj| } Returns elements sorted according to keys produced by block
to_a             Returns an Array of all objects, alias for entries
to_set           Creates a Set from elements, must require "set"
zip(args, ...)   Merges elements with corresponding elements from each arg
Version 1, updated 344 days ago.
. o 0 ( | history | revert to | current | diff )
( add new | see all )