Posted By

DrPepper on 05/26/11


Tagged


Versions (?)

inherited class


 / Published in: Ruby
 

Mammal class as "super class" cat class as "sub class"

  1. ruby> class Mammal
  2. | def breathe
  3. | puts "inhale and exhale"
  4. | end
  5. | end
  6. nil
  7. ruby> class cat<Mammal
  8. | def speak
  9. | puts "Meow"
  10. | end
  11. | end
  12. ERR: <main>: class/module name must be CONSTANT
  13. class cat<Mammal
  14. ^
  15. ruby> class Cat< Mammal
  16. | def speak
  17. | puts "Meow"
  18. | end
  19. | end
  20. nil
  21. ruby> tama = Cat.new
  22. #<Cat:0x00000001094628>
  23. ruby> tama.breathe
  24. inhale and exhale
  25. nil
  26. ruby> tama.speak
  27. Meow
  28. nil

Report this snippet  

You need to login to post a comment.