Skip to content

Instantly share code, notes, and snippets.

@luislavena
Created January 6, 2017 17:34
Show Gist options
  • Save luislavena/54ee4bb36a8b133ffaac2fdf3cbf090c to your computer and use it in GitHub Desktop.
Save luislavena/54ee4bb36a8b133ffaac2fdf3cbf090c to your computer and use it in GitHub Desktop.
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