Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8218867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:56:55+00:00 2026-06-07T12:56:55+00:00

Lately I came across some weird behavior with the defined? operator used to check

  • 0

Lately I came across some weird behavior with the defined? operator used to check if super keyword can be used 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.

It’s easier to show then to describe, so here is a distilled example to illustrate the problem:

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

(A and AA classes both have .def_f! class method)

A.def_f!

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

(A.f has no super and AA.f dispatches to A.f, so everything’s OK so far, but…)

AA.def_f! # define its own .f method in the AA class

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

Could anyone explain me the last line? A.f has no super method, then why it returns "super" instead of nil? Is it a bug?

(I tried it in 1.9.2 and 1.9.3—same results)

UPD: I opened a ticket on the Ruby bugtracker: http://bugs.ruby-lang.org/issues/6644

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T12:56:56+00:00Added an answer on June 7, 2026 at 12:56 pm

    Ok, so @Niklas was right, I reported this issue to the Ruby bugtracker and they confirmed and fixed the bug: https://bugs.ruby-lang.org/issues/6644.

    As far as I’ve understood, the fix will be included in ruby 2.0.0.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been reading over some code lately and came across some lines such
I've been learning Objective C lately, and I came across some code for using
Doing some code reviews lately I came across a number of classes that have
I've been trying to self-teach some OOP lately, and I came across something which
I've been working with PHP lately, and I came across something I couldn't solve.
I've been reading on Generics lately, and I came across this method: protected <V>
I've been doing a lot of knockoutjs lately, and I came across a strange
Lately, I've gotten some weird linker errors. I've been taught that there's two ways
I've been practicing certain techniques in XNA and lately came across an issue that's
I've been fiddling with flash lately and I came across this issue. I've noticed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.