Skip to content

Instantly share code, notes, and snippets.

@kevinthompson
Created July 6, 2013 17:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinthompson/5940647 to your computer and use it in GitHub Desktop.
Save kevinthompson/5940647 to your computer and use it in GitHub Desktop.
Unary Ampersand Example: Proc to Block
items = {
'a' => 'aardvark',
'b' => 'banana',
'c' => 'cookies',
'd' => 'dog'
}
criteria = Proc.new { |key, value| value == 'banana' }
items.select(&criteria) # => {"b"=>"banana"}
items.reject(&criteria) # => {"a"=>"aardvark", "c"=>"cookies", "d"=>"dog"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment