Access inner classes : nested classes « Class « Ruby






Access inner classes

class Drawing
  def Drawing.give_me_a_circle
    Circle.new
  end

  class Line
  end

  class Circle
    def what_am_i
      "This is a circle"
    end
  end
end

a = Drawing.give_me_a_circle
puts a.what_am_i
a = Drawing::Circle.new
puts a.what_am_i
a = Circle.new
puts a.what_am_i

 








Related examples in the same category

1.Place classes within other classes. These are called nested classes.