Last active
December 16, 2015 12:09
-
-
Save freshtonic/5433032 to your computer and use it in GitHub Desktop.
Bound methods as blocks in Ruby
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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