Created
January 6, 2017 17:34
-
-
Save luislavena/54ee4bb36a8b133ffaac2fdf3cbf090c 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
struct Wrapper(T) | |
module Interface | |
abstract def unwrap | |
end | |
include Interface | |
def unwrap | |
T | |
end | |
end | |
module Action | |
abstract def call | |
end | |
class Foo | |
include Action | |
def call | |
puts "Foo!" | |
end | |
end | |
class Bar | |
include Action | |
def call | |
puts "Bar!" | |
end | |
end | |
ary = [] of Wrapper::Interface | |
ary << Wrapper(Bar).new | |
ary << Wrapper(Foo).new | |
ary.each do |item| | |
klass = item.unwrap | |
instance = klass.new | |
instance.call | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment