RubyGems Navigation menu

filter 0.0.6

Synopsys

Enumerable#filter - extended Enumerable#select

Examples

String filter (acts like Enumerable#grep):

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

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

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

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

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

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

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

Enumerable#filter also accepts true or false as argument:

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

Enumerable#filter also supports OR operator! Just pass many patterns, they will be joined together with OR operator.

[0, 2, 3, 4].filter(:zero?, :odd?)       # => [0, 3]

Gemfile:
=

インストール:
=

バージョン履歴:

  1. 0.0.6 December 12, 2011 (8KB)
  2. 0.0.5 December 12, 2011 (8KB)
  3. 0.0.4 December 12, 2011 (7KB)
  4. 0.0.3 December 11, 2011 (6.5KB)
  5. 0.0.2 December 11, 2011 (6.5KB)
全てのバージョンを表示(全6件)

Development依存関係 (1):

rspec >= 0

所有者:

作者:

  • Alexey Mikhaylov

SHA 256チェックサム:

=

累計ダウンロード数 23,761

このバージョンのみ 6,039

このバージョンがリリースされたのは:

ライセンス:

N/A

必要なRubyのバージョン: なし

リンク: