Ruby/Reflection/Module Reflection
Материал из Wiki.crossplatform.ru
(Различия между версиями)
ViGOur (Обсуждение | вклад) м (1 версия: Импорт выборки материалов по Ruby) |
Текущая версия на 17:57, 13 сентября 2010
Discover the names of any of the included modules of an instance or its class using the included_modules method from Module.
myString = "asdf" p myString.class.included_modules # => [Enumerable, Comparable, Kernel] p myString.class.superclass.included_modules # => [Kernel] p String.included_modules # => [Enumerable, Comparable, Kernel] p Object.included_modules # => [Kernel]
use the included_modules method to discover what modules a class uses
puts Object.included_modules # => [Kernel] puts Numeric.included_modules # => [Comparable, Kernel] puts Integer.included_modules # => [Precision, Comparable, Kernel] puts Fixnum.included_modules # => [Precision, Comparable, Kernel]