Created
December 13, 2012 18:44
-
-
Save noahhendrix/4278614 to your computer and use it in GitHub Desktop.
Just playing around with call (from RubyTapas #35)
This file contains 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 Content | |
def initialize(options={}) | |
@notifier = options.fetch(:notifier) { | |
->(user) { puts "#{user.name}, you won!" } | |
} | |
end | |
def choose_winner | |
winner = User.new | |
@notifier.call(winner) | |
end | |
end | |
class User | |
def name | |
"Bob" | |
end | |
def send_sms(*args) | |
puts "beboop" | |
end | |
end | |
Content.new.choose_winner | |
Content.new(notifier: :send_sms.to_proc).choose_winner |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment