Feature #7339
closedVersion of super that doesn't raise when super undefined
Description
=begin
I propose new method try_super (it's possibly bad name, any suggestions) which would work like a super except not raising in case that super method undefined. It can be useful in such a situation - when module makes smth useful even in absence of super class.
I use an example with Module#prepend, but similar example with Module#include can be created with a bit more effort.
module MyLogging
def info(*args)
$stderr.puts "Hello! You've an info message"
super # with super it raises when super undefined
end
end
require 'logger'
class Logger
prepend MyLogging
end
class Foo
prepend MyLogging
end
Logger.new.info 'message'
Foo.new.info 'message'
In an example Foo.new.info raises an exception while really it shouldn't in my opinion. So try_super can be used
If it doesn't broke many libraries (I believe not many of them uses super in cases when it raises), super can be renamed to 'super!' and more mild version can be 'super'.
=end