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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:58:14+00:00 2026-05-13T11:58:14+00:00

Why is is that the following fails? module Test def test puts test end

  • 0

Why is is that the following fails?

module Test
    def test
        puts "test"
    end

    puts "testing"
    test
end

I get this output:

testing
test.rb:6:in `test': wrong number of arguments (ArgumentError)
    from test.rb:6:in `<module:Test>'
    from test.rb:1:in `<main>'

Is it because the module hasn’t been “compiled” yet, since the end keyword hasn’t been reached?

  • 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-13T11:58:14+00:00Added an answer on May 13, 2026 at 11:58 am

    Using a previously unused name might clear up your confusion:

    module Test
      def my_test
        puts "my_test"
      end
      puts "testing"
      my_test
    end
    

    results in

    testing
    NameError: undefined local variable or method `my_test' for Test:Module
    

    Inside the module...end block, when you invoke my_test, what is self (the implicit receiver)? It is the module Test. And there is no my_test “module method”. The my_test method defined above is like an instance method, to be sent to some object that includes this module.

    You need to define my_test as a “module method”:

    module Test
      def self.my_test
        puts "my_test"
      end
      puts "testing"
      my_test
    end
    

    results in

    testing
    my_test
    

    If you want my_test as an instance method and you want to invoke it inside your module definition:

    method Test
      puts "testing"
      Object.new.extend(self).my_test
    end
    

    gives

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

Sidebar

Related Questions

I have the following init method in a gen_fsm callback module (my_fsm): init(Args) when
sI have an XML file that looks like the following... <a> <b> <version>1.0</version> <c>
I have a HTTP module that I have written that needs to access the
I have a Sharepoint IRM module that works most of the time. However, most
I need to translate the following LINQ query to Dynamic LINQ that accepts several
I am writing unit tests to validate a profile avatar module. So, I have
I'm trying to enable passthrough or impersonation authentication inside an ASP.NET website that uses
I ran into an issue that can only be explained with my fundamental lack
I am using django-nonrel. When I run manage.py test over my project which contains
I'm using PRISM in a SilverLight 4 application. I have a problem where views

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.