Classes and Inheritance


#1

why is this code not displaying Error! Error! that was defined in the first class ? note my comments# on the line before last. I just want to understand why is it that i have to create another variable = .new ?


class ApplicationError
  def display_error
    puts "Error! Error!"
  end
end

class SuperBadError < ApplicationError
end

#err = SuperBadError.new
#err.display_error

puts SuperBadError

output =>

Context::SuperBadError
nil

isnt this:
class SuperBadError < ApplicationError
end

a way of showing that i inherited the attributes from ApplicationError to SuperBadError ? if so why can't i just say :
puts SuperBadError ? it makes sense this way but making another .new method is confusing


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.