Class: Hash

Inherits:
Object show all
Defined in:
lib/monkey_patches.rb

Overview

Monkey Patch for Hash

Instance Method Summary collapse

Instance Method Details

#filter(*args) ⇒ Hash

add a filter function to Hash Class

Examples:

tags = [ 'foo', 'bar', 'fii' ]
useableTags = tags.filter( 'fii' )

Returns:



80
81
82
83
84
85
86
87
# File 'lib/monkey_patches.rb', line 80

def filter( *args )
  if( args.size == 1 )
    args[0] = args[0].to_s if  args[0].is_a?( Symbol )
    select { |key| key.to_s.match( args.first ) }
  else
    select { |key| args.include?( key ) }
  end
end