mynyml / every
- Source
- Commits
- Network (5)
- Issues (1)
- Downloads (4)
- Wiki (1)
- Graphs
-
Branch:
chaining-alt
every /
| name | age | message | |
|---|---|---|---|
| |
LICENSE | Sun Mar 15 22:34:46 -0700 2009 | |
| |
README | ||
| |
Rakefile | ||
| |
TODO | Mon Mar 16 07:06:29 -0700 2009 | |
| |
benchmarks.rb | ||
| |
every.gemspec | ||
| |
examples.rb | ||
| |
lib/ | ||
| |
test/ |
README
Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables.
compare:
enum = [1.4, 2.4 ,3.4]
enum.map {|i| i.floor } #=> [1, 2, 3]
enum.map(&:floor) #=> [1, 2, 3]
enum.every.floor #=> [1, 2, 3]
arguments? sure:
%w( axb dxf ).every.gsub(/x/,'y') #=> ['ayb', 'dyf']
%w( axb dxf ).every.gsub(/x/) { 'y' } #=> ['ayb', 'dyf']
need to call multiple methods? there's a shortcut:
enum.every.floor.every.next.every + 2 #=> [4,5,6]
enum.every { floor.next + 2 } #=> [4,5,6]
like #map, but right to the point.

