Guest User

Untitled

a guest
Jul 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1.  
  2. class Dog
  3. attr_accessor :name, :breed, :age
  4. @@num_of_dogs=0
  5. def initialize(name, breed, age)
  6. @name=name
  7. @breed=breed
  8. @age=age
  9. puts "dog number: #{@@num_of_dogs} has been created.
  10. Name: #{@name}
  11. Breed: #{@breed}
  12. Age: #{@age}"
  13. @@num_of_dogs+=1
  14. end
  15. def bark(s)
  16. puts s
  17. end
  18. def bark
  19. puts "waff waff!! I'm a dog"
  20. end
  21. end
  22.  
  23. require "dogg.rb"
  24. class Collie < Dog
  25. attr_accessor :color
  26. @@num_of_collies=0
  27. def initialize(s, a, n)
  28. @color=s
  29. super(n,"collie", a)
  30. puts "color: #{@color}"
  31. end
  32. def bark
  33. if color == "brown"
  34. super.bark *****************************************************
  35. else
  36. puts "waff waff!! i'm a collie"
  37. end
  38. end
  39. end
  40.  
  41. require "collie.rb"
  42. #c = Collie.new
  43. #c.bark
  44. cc=Collie.new("gold", 74, "bobik")
  45. cc.bark
  46. c=Collie.new("brown", 2, "palkan")
  47. c.bark
  48.  
  49.  
  50. ./collie.rb:12:in `bark': undefined method `bark' for nil:NilClass (NoMethodError)
  51. from stack.rb:7
  52. dog number: 0 has been created.
  53. Name: bobik
  54. Breed: collie
  55. Age: 74
  56. color: gold
  57. waff waff!! i'm a collie
  58. dog number: 1 has been created.
  59. Name: palkan
  60. Breed: collie
  61. Age: 2
  62. color: brown
  63. waff waff!! I'm a dog
  64.  
  65.  
  66. Can anyone tell me what the error about?
  67. I marked the line 12 in collie.rb with ***********************************
Add Comment
Please, Sign In to add comment