Ruby/Class/nested classes

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

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



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

class Drawing
  class Line
  end
  class Circle
  end
end