From: Nathan Broadbent Date: 2012-11-13T05:37:56+09:00 Subject: [ruby-core:49264] Re: [ruby-trunk - Feature #7339][Open] Version of super that doesn't raise when super undefined --e89a8fb206cea8b66c04ce524680 Content-Type: text/plain; charset=ISO-8859-1 We can already write: super if defined?(super) I don't think a shortcut would be necessary for that, since it's already quite short. Best, Nathan On Tuesday, 13 November 2012, prijutme4ty (Ilya Vorontsov) wrote: > > Issue #7339 has been reported by prijutme4ty (Ilya Vorontsov). > > ---------------------------------------- > Feature #7339: Version of super that doesn't raise when super undefined > https://bugs.ruby-lang.org/issues/7339 > > Author: prijutme4ty (Ilya Vorontsov) > Status: Open > Priority: Normal > Assignee: > Category: > Target version: > > > =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 > > > > -- > http://bugs.ruby-lang.org/ > > --e89a8fb206cea8b66c04ce524680 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable We can already write:

=A0 =A0 super if defined?(super)

I don't think a shortcut would be necessary for= that, since it's already quite short.


Best,
Nathan

On Tuesday, 13 Nov= ember 2012, prijutme4ty (Ilya Vorontsov) wrote:

Issue #7339 has been reported by prijutme4ty (Ilya Vorontsov).

----------------------------------------
Feature #7339: Version of super that doesn't raise when super undefined=
https:= //bugs.ruby-lang.org/issues/7339

Author: prijutme4ty (Ilya Vorontsov)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


=3Dbegin
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 metho= d 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#inclu= de can be created with a bit more effort.

=A0 module MyLogging
=A0 =A0 def info(*args)
=A0 =A0 =A0 $stderr.puts "Hello! You've an info message"
=A0 =A0 =A0 super # with super it raises when super undefined
=A0 =A0 end
=A0 end

=A0 require 'logger'
=A0 class Logger
=A0 =A0 prepend MyLogging
=A0 end


=A0 class Foo
=A0 =A0 prepend MyLogging
=A0 end

=A0 Logger.new.info 'message'
=A0
Foo.new.info '= ;message'


In an example Foo.new.inf= o raises an exception while really it shouldn't in my opinion. So t= ry_super can be used

If it doesn't broke many libraries (I believe not many of them uses sup= er in cases when it raises), super can be renamed to 'super!' and m= ore mild version can be 'super'.

=3Dend



--
http://bugs.ruby-l= ang.org/

--e89a8fb206cea8b66c04ce524680--