A small test case :
class A
def self.print
puts "Hello A"
end
end
class B < A
end
A.print
B.print
This outputs :
Hello A
Hello A
I would like to block the inheritance of the print function defined in class A. Is it possible?
Output wanted :
Hello A
`<main>': undefined method `print' for B:Class (NoMethodError)
I found private_class_method but it's not exaclty what I'm looking for as it fails on A.print call.
class A
def self.print
puts "Hello A"
end
def self.inherited(klass)
class << klass
undef :print
end
end
end
class B < A
end
A.print
# Hello A
B.print
# private method `print' called for B:Class (NoMethodError)
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