Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
class Apple
|
||||
def eat
|
||||
end
|
||||
end
|
||||
|
||||
class Carrot
|
||||
def eat
|
||||
end
|
||||
end
|
||||
|
||||
class FoodBox(T)
|
||||
def initialize(@data : Array(T))
|
||||
{% if T.union? %}
|
||||
{% raise "All items should be eatable" unless T.union_types.all? &.has_method?(:eat) %}
|
||||
{% else %}
|
||||
{% raise "Items should be eatable" unless T.has_method?(:eat) %}
|
||||
{% end %}
|
||||
end
|
||||
end
|
||||
|
||||
FoodBox.new([Apple.new, Apple.new])
|
||||
FoodBox.new([Apple.new, Carrot.new])
|
||||
FoodBox.new([Apple.new, Carrot.new, 123])
|
||||
Loading…
Add table
Add a link
Reference in a new issue