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

Why does the following JavaScript script open a new window, but fails to scroll
I copied a Django directory named 'politifact' to 'politifact_omniture-1.0' to test new analytics code.
I have two tables: Accounts , which contains the information of accounts that a
The following is a sample string I'm using:  http://www.asfradio.com/device.asp?u=username&p=password&s=east Current checks I use in
I am using the following to search a directory recursively for specific string and
I'm trying to integrate Django's comment app into my site but with no success.
I'm trying to refactor some python code and I'm stuck with an import error
I've been working up my answer to Is there a standard Scala function for
I have just upgraded to jruby 1.6.1 and when I run in 1.9 mode,
I believe the issue below relates to variable scope, although I may be mistaken.

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.