Skip to content

Instantly share code, notes, and snippets.

@phinze
Created May 3, 2012 05:14
Show Gist options
  • Save phinze/2583389 to your computer and use it in GitHub Desktop.
Save phinze/2583389 to your computer and use it in GitHub Desktop.
simple dynamic dispatch example
class DisinterestedCat
def speak
puts "..."
end
def play
puts "...<look away>"
end
end
fluffy = DisinterestedCat.new
fluffy.send(:speak)
# => "..."
fluffy.send("play".to_sym)
# => "...<look away>"
puts fluffy.respond_to?(:play)
# => true
puts fluffy.respond_to?(:sit)
# => false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment