DEV Community

pooyaalamdari
pooyaalamdari

Posted on

inheritance ruby

class Publication 
    attr_accessor :publisher
end

class Magazine < Publication
    attr_accessor :editor 
end

mag = Magazine.new 
mag.publisher = "David A. Black"
mag.editor = "Joe Smith"
puts "Mag published by #{mag.publisher}, and edited by #{mag.editor}."
Enter fullscreen mode Exit fullscreen mode
class Person 
    def species 
        "Homo sapiens"
    end
end

class Rubyist < Person

end

david = Rubyist.new

puts david.species
Enter fullscreen mode Exit fullscreen mode

Top comments (0)