RubyGems Navigation menu

filter 0.0.1

Synopsys

Enumerable#filter - extended Enumerable#select

Examples

String filter (acts like Enumerable#grep):

[1, 2, 3, 'ab'].filter(/a/)              # => #<Enumerator: ['ab']>
[1, 2, 3, '3'].filter('3')               # => #<Enumerator: ['3']>

You can pass a Proc or Symbol. Methods and blocks are allowed too:

[1, 2, 3].filter(&:even?)                # => #<Enumerator: [2]>
[1, 2, 3].filter(:even?)                 # => #<Enumerator: [2]>
[1, 2, 4].filter { |num| num.even? }     # => #<Enumerator: [2, 4]>

Enumerable#filter can match against enumerable items attributes. Like this:

[1, 2, 3, 4.2].filter :to_i => :even?    # => #<Enumerator: [2, 4]>

If the block is supplied, each matching element is passed to it, and the block’s result is stored in the output enumerator.

[1, 2, 4].filter(&:even?) { |n| n + 1 }  # => #<Enumerator: [3, 5]>

Enumerable#filter also accepts true or false as argument:

[0, false, 2, nil].filter(true)          # => #<Enumerator: [0, 2]>
[0, false, 2, nil].filter(false)         # => #<Enumerator: [false, nil]>

Gemfile:
=

instalar:
=

Versões:

  1. 0.0.6 December 12, 2011 (8 KB)
  2. 0.0.5 December 12, 2011 (8 KB)
  3. 0.0.4 December 12, 2011 (7 KB)
  4. 0.0.3 December 11, 2011 (6,5 KB)
  5. 0.0.2 December 11, 2011 (6,5 KB)
  6. 0.0.1 December 10, 2011 (7 KB)
Mostrar todas as versões (6)

Development Dependencies (1):

rspec >= 0

Donos:

Autores:

  • Alexey Mikhaylov

SHA 256 checksum:

=

Total de downloads 23.766

Desta versão 3.544

Versão lançada:

Licenças:

N/A

Versão Requerida do Ruby: Nenhum

Links: