Module and class hierarchy
module A
end # Empty module
module B
include A
end # Module B includes A
class C
include B
end # Class C includes module B
puts C < B # => true: C includes B
puts B < A # => true: B includes A
puts C < A # => true
puts Fixnum < Integer # => true: all fixnums are integers
puts Integer <Comparable # => true: integers are comparable
puts Integer < Fixnum # => false: not all integers are fixnums
puts String < Numeric # => nil: strings are not numbers
puts A.ancestors # => [A]
puts B.ancestors # => [B, A]
puts C.ancestors # => [C, B, A, Object, Kernel]
puts String.ancestors # => [String, Enumerable, Comparable, Object, Kernel]
# Note: in Ruby 1.9 String is no longer Enumerable
puts C.include?(B) # => true
puts C.include?(A) # => true
puts B.include?(A) # => true
puts A.include?(A) # => false
puts A.include?(B) # => false
puts A.included_modules # => []
puts B.included_modules # => [A]
puts C.included_modules # => [B, A, Kernel]
Related examples in the same category