Skip to content

Instantly share code, notes, and snippets.

@noahhendrix
Created December 13, 2012 18:44
Show Gist options
  • Save noahhendrix/4278614 to your computer and use it in GitHub Desktop.
Save noahhendrix/4278614 to your computer and use it in GitHub Desktop.
Just playing around with call (from RubyTapas #35)
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