Skip to content

Instantly share code, notes, and snippets.

@freshtonic
Last active December 16, 2015 12:09
Show Gist options
  • Save freshtonic/5433032 to your computer and use it in GitHub Desktop.
Save freshtonic/5433032 to your computer and use it in GitHub Desktop.
Bound methods as blocks in Ruby
class WhiteList
def initialize(names)
@names = names
end
def whitelisted?(name)
@names.include? name
end
end
w = WhiteList.new %w(Alice Bob)
%w(Alice Bob John Mark James).select &w.method(:whitelisted?) => ['Alice', 'Bob']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment