Guest User

Untitled

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