Yesterday, I found the following code in RSpec:
class OptionParser < ::OptionParser
What does this do? What is the difference between this and class OptionParser < NameSpace::OptionParser
?
An runnable example might explain the idea best:
class C
def initialize
puts "At top level"
end
end
module M
class C
def initialize
puts "In module M"
end
end
class P < C
def initialize
super
end
end
class Q < ::C
def initialize
super
end
end
end
M::P.new
M::Q.new
Produces when run:
In module M
At top level
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With