Created
March 26, 2016 07:28
-
-
Save igaiga/0407b647602da14e7de7 to your computer and use it in GitHub Desktop.
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
module Helloable | |
def hello | |
"hello" | |
end | |
end | |
class Cat | |
def hello | |
"nya" | |
end | |
end | |
class Dog | |
def hello | |
"wan" | |
end | |
end | |
class Fish | |
include Helloable | |
end | |
class Human | |
include Helloable | |
end | |
class Cage | |
def initialize(animal) | |
@animal = animal | |
end | |
def hello | |
if @animal.respond_to?(:hello) | |
p @animal.hello | |
else | |
p "..." | |
end | |
end | |
end | |
cage = Cage.new(Fish.new) | |
cage.hello |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment