Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created March 26, 2016 07:28
Show Gist options
  • Save igaiga/0407b647602da14e7de7 to your computer and use it in GitHub Desktop.
Save igaiga/0407b647602da14e7de7 to your computer and use it in GitHub Desktop.
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