stack_1.sf 315 B

1234567891011121314151617
  1. #!/usr/bin/ruby
  2. #
  3. ## https://rosettacode.org/wiki/Stack
  4. #
  5. class Stack(stack=[]) {
  6. method pop { stack.pop };
  7. method push(item) { stack.push(item) };
  8. method empty { stack.is_empty };
  9. }
  10.  
  11. var stack = Stack();
  12. stack.push(42);
  13. say stack.pop; # => 42
  14. say stack.empty; # => true