In my previous post I talked about interfaces. In this one I just do simple inheritance with the same classes as in the previous post. More difficult scenarios are possible but We should watch out with inheritance because it can get to complex very fast. Try to avoid complex inheritance trees.


class Plant

  attr_accessor :name


class Animal < Plant


Yes Animals inherit from Plants because they share the same property so there.

And still running the same test.

``` require ‘rubygems’ gem ‘test-unit’ require “test/unit” require_relative “plant”

class Test_plant < Test::Unit::TestCase

def test_check_if_Plant_and_Animal_both_have_name my_plant = my_animal = = “test” = “test” my_array = [my_animal,my_plant] my_array.each { |x| assert_equal(“test”,,“The name is not test”)} end end``` Which still turns green

and red like before.


Simple inheritance is not that difficult, but you can easily make it a lot more difficult. I think I have now the basis to start reading code others wrote and learn more from that.