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 6023125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:57:32+00:00 2026-05-23T03:57:32+00:00

With the following code: class ObjA def func puts ObjA end end module Mod

  • 0

With the following code:

class ObjA
    def func
        puts "ObjA"
    end
end

module Mod
    def func
        puts "Mod"
    end
end

class ObjB < ObjA
    include Mod
    def func
        puts "super called"
        super
        puts "super.func called"
        super.func
    end
end

Running ObjB.new.func results in:

ruby-1.9.2-p180 :002 > ObjB.new.func
super called
Mod
super.func called
Mod
NoMethodError: undefined method `func' for nil:NilClass
    from test.rb:19:in `func'
    from (irb):2

I understand what super does – it calls the current method on the superclass. include Mod makes Mod the next superclass so Mod#func is called.

However, what is super.func doing? I thought it would be equivalent to super, but while it does print out the same output, it also throws a NoMethodError.

  • 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-05-23T03:57:32+00:00Added an answer on May 23, 2026 at 3:57 am

    I assume super.func would do the same thing as any form of method chaining. It calls super, and then calls func on the result returned by super.

    The super part would call Mod#func, which prints out “Mod”, then calls func on the return value of Mod#func, ie nil (that’s because puts returns nil). As nil doesn’t have a func method, it says

    NoMethodError: undefined method `func' for nil:NilClass
        from test.rb:19:in `func'
        from (irb):2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: class IncidentTag: def __init__(self,tag): self.tag = tag def equals(self,obj):
To illustrate the question check the following code: class MyDescriptor(object): def __get__(self, obj, type=None):
I have the following example code: class A(object): def __init__(self, id): self.myid = id
In Python 2.5, the following code raises a TypeError : >>> class X: def
The following code class Schedule < ActiveRecord::Base def self.get today = TZInfo::Timezone.get('America/New_York').utc_to_local(Time.now.utc).to_date end end
The following code: class Log: BAT_STATS = ['AB', 'R', 'H', 'HR'] def __init__(self, type):
The following code: class MyClass(): def test(self): self.__x = 0 def __setattr__(self, name, value):
Suppose I have the following code: class some_class{}; some_class some_function() { return some_class(); }
Suppose I have the following code: class siteMS { ... function __CONSTRUCT() { require
Is there any difference to the following code: class Foo { inline int SomeFunc()

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.