mynyml / every

Symbol#to_proc's hot cousin. Simple and elegant alternative to using &:method with enumerables.

This URL has Read+Write access

every /
name age message
file .gitignore Loading commit data...
file LICENSE Sun Mar 15 22:34:46 -0700 2009 Add license. [mynyml]
file README
file Rakefile
file TODO Mon Mar 16 07:06:29 -0700 2009 Add TODO list. [mynyml]
file benchmarks.rb
file every.gemspec
file examples.rb
directory lib/
directory 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']

-----
experimental: #select/#reject

  %w( foo bar baz ).select_every.match(/^ba/).inspect #=> ['bar', 'baz']
  %w( foo bar baz ).reject_every.match(/^ba/).inspect #=> ['foo']