Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Dog
- attr_accessor :name, :breed, :age
- @@num_of_dogs=0
- def initialize(name, breed, age)
- @name=name
- @breed=breed
- @age=age
- puts "dog number: #{@@num_of_dogs} has been created.
- Name: #{@name}
- Breed: #{@breed}
- Age: #{@age}"
- @@num_of_dogs+=1
- end
- def bark(s)
- puts s
- end
- def bark
- puts "waff waff!! I'm a dog"
- end
- end
- require "dog.rb"
- class Collie < Dog
- attr_accessor :color
- @@num_of_collies=0
- def initialize(s, a, n)
- @color=s
- super(n,"collie", a)
- puts "color: #{@color}"
- end
- def bark
- if color == "brown"
- super.bark ***********************************************
- else
- puts "waff waff!! i'm a collie"
- end
- end
- end
- require "collie.rb"
- cc=Collie.new("gold", 74, "bobik")
- cc.bark
- c=Collie.new("brown", 2, "palkan")
- c.bark
- ./collie.rb:12:in `bark': undefined method `bark' for nil:NilClass (NoMethodError)
- from stack.rb:7
- dog number: 0 has been created.
- Name: bobik
- Breed: collie
- Age: 74
- color: gold
- waff waff!! i'm a collie
- dog number: 1 has been created.
- Name: palkan
- Breed: collie
- Age: 2
- color: brown
- waff waff!! I'm a dog
- can anyone tell me what's the error about?
- I marked the line 12 in collie.rb with ****************************
Add Comment
Please, Sign In to add comment