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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:56:08+00:00 2026-06-01T02:56:08+00:00

When answering another question, I realized that the following program does not quite do

  • 0

When answering another question, I realized that the following program does not quite do what I thought it does.

puts "test"
self.puts "test"  # => private method `puts' called for main:Object (NoMethodError)

The exception surprises me, as I always thought that top-level method calls would be resolved by the main object instance, but this doesn’t seem to be the case.

Who’s the actual receiver of the first call and how is it resolved? Is this a special rule that only applies to method calls at the top-level scope?

  • 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-01T02:56:09+00:00Added an answer on June 1, 2026 at 2:56 am

    Here is a good discussion that talks about this question.

    The top level methods, which are provided by Kernel, are automatically included to the Object class. This means the Kernel methods will appear in everything.

    The error private method 'puts' called for main:Object (NoMethodError) is just stating that puts exists but is privately scoped.

    ree-1.8.7-2011.03 :001 > puts "test"
    test
    ree-1.8.7-2011.03 :004 > self.send(:puts, "hi" )
    hi
    

    UPDATE

    There is no magic for Kernel methods. There is no scope hopping or anything. I think the confusion lines in what the scope is when using self. You do not have access to private methods using self.

    class PutsTest
    
      def success_puts
        private_puts
      end
    
      def failed_puts
        # trying to access a private method from self
        self.private_puts
      end
    
      private
    
      def private_puts
       puts 'hi'
      end
    end
    

    By using self, you are changing the scope from calling the method inside of PutsTest to calling from the outside of PutsTest

    ree-1.8.7-2011.03 :095 > test = PutsTest.new
    ree-1.8.7-2011.03 :096 > test.success_puts
    hi
    ree-1.8.7-2011.03 :097 > test.failed_puts
    NoMethodError: private method `private_puts' called for #<PutsTest:0xd62c48>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While answering another question, I thought of the following example: void *p; unsigned x
In answering another persons question here on SO, I discovered that there is a
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
Before answering, it is not as easy question as you might have thought about
As part of answering another question, I wanted to show that the insane level
I want to create a script that does the following: When answering questions via
In answering another question I created the following script bash script: #!/bin/bash files1=( file1.txt
As part of answering another question, I wrote the following code whose behaviour seems
When answering another question I started to wonder how I could Add new properties
As part of answering another question, I came across a piece of code like

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.