RosettaCodeData/Task/Constrained-genericity/Sidef/constrained-genericity.sidef
2023-07-01 13:44:08 -04: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)