oop/module_superclass/undefined.rb

tests/_examples/oop/module_superclass/undefined.rb in the metorex repository.

# A module has no superclass and does not answer `superclass`, while every
# class does.
module Greetings
end

puts Greetings.respond_to?(:superclass)
begin
  Greetings.superclass
rescue NoMethodError => error
  puts error.message
end
puts Class.new.superclass.inspect
puts BasicObject.superclass.inspect

Output:

false
undefined method 'superclass' for module Greetings
Object
nil