Created
September 18, 2019 16:12
-
-
Save djmetzle/e54247043f97b1935ff7126311e36e5e to your computer and use it in GitHub Desktop.
Class dispatch
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
class Foo | |
def quack | |
puts "quack" | |
end | |
end | |
class Bar | |
def bark | |
puts "woof" | |
end | |
end | |
class Dispatcher | |
def dispatch obj | |
puts "dispatch #{obj.class}" | |
case obj | |
when Foo | |
obj.quack | |
when Bar | |
obj.bark | |
else | |
raise "WaT" | |
end | |
end | |
end | |
f = Foo.new | |
b = Bar.new | |
x = Object.new | |
d = Dispatcher.new | |
d.dispatch f | |
d.dispatch b | |
d.dispatch x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment