Skip to content
nkpart edited this page Sep 13, 2010 · 3 revisions

Accidentally is for finding the name of function, given you know what you want to achieve:
eg.

> [1,2,3].accidentally == 3
=> [“last”, “pop”, “length”, “size”, “nitems”, “max”]

> [1,nil,3,5].accidentally == [1,3,5]
=> [“select”, “compact”, “compact!”, “find_all”]

> [:a, :b, :c].accidentally(:b) == 1
=> [“index”, “rindex”]

> [:a, :b, :c, :d].accidentally(2,3) == [:c, :d]
=> [“slice”, “indexes”, “values_at”, “indices”, “slice!”, “[]”]

> “abc”.accidentally(/\w/) == [“a”,“b”,“c”]
=> [“scan”]

> [1,2,3,4,5].accidentally{|a,b| a + b} == 15
=> [“inject”]

Clone this wiki locally