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)

We're hiring!

We're Hiring

We're looking for someone who can develop, maintain, and implement our product roadmap and strategy as a Senior Product Manager.

Head here to learn more.