Project

General

Profile

Actions

Bug #6644

closed

Weird behavior of defined?(super) check invoked from a metaprogrammatically defined class method

Added by alexisowl (Alexey Smolianinov) almost 12 years ago. Updated over 11 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.3p0 (2011-10-30 revision 33570) [i686-linux]
Backport:
[ruby-core:45831]

Description

=begin
Lately I came across some weird behavior with the (({defined?})) operator used to check if (({super})) keyword can be invoked in current context. Usually it works fine, but when I tried to combine the (({defined? super})) check with a tiny bit of metaprogramming, it gave me unexpected results.

Here's an example:

class A;
def self.def_f!;
singleton_class.send(:define_method, :f) { defined? super }
end
end
class AA < A; end

A.def_f!

A.f # => nil
AA.f # => nil

AA.def_f!

AA.f # => "super"
A.f # => "super" - WHY???

The last result is really strange, isn't it?

A.f has no super method, so I would expect the last (({A.f})) to return (({nil})).
Is it a bug?

=end


Related issues 2 (0 open2 closed)

Related to Backport200 - Backport #8367: regression in defined?(super) starting with 2.0.0-p0Closednagachika (Tomoyuki Chikanaga)05/04/2013Actions
Has duplicate Ruby master - Bug #6722: Weird behavior of defined?(super) check invoked from a metaprogrammatically defined class methodClosed07/11/2012Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0