RosettaCodeData/Task/Constrained-genericity/Sidef/constrained-genericity.sidef
2016-12-05 23:44:36 +01:00

7 lines
274 B
Text

class FoodBox(*food { .all { .respond_to(:eat) } }) { }
class Fruit { method eat { ... } }
class Apple < Fruit { }
say FoodBox(Fruit(), Apple()).dump #=> FoodBox(food: [Fruit(), Apple()])
say FoodBox(Apple(), "foo") #!> ERROR: class `FoodBox` !~ (Apple, String)