Ruby/Class/nested classes

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

Версия от 17:55, 13 сентября 2010; ViGOur (Обсуждение | вклад)
(разн.) ← Предыдущая | Текущая версия (разн.) | Следующая → (разн.)
Перейти к: навигация, поиск

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