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

  • Home
  • SEARCH
  • 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 7854575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T20:06:24+00:00 2026-06-02T20:06:24+00:00

I ruby 1.8.7, Why I can use require in main, but can’t use self.require?

  • 0

I ruby 1.8.7, Why I can use require in main, but can’t use self.require?

require('date') # ok
self.require('date') 
NoMethodError: private method `require' called for main:Object
from (irb):22
from /usr/lib/ruby/1.8/date.rb:437

Well known that main is Object class:
irb(main):045:0> self
=> main

irb(main):043:0> self.class
=> Object

But I discovered that it have Kernel mixin:

irb(main):042:0> self.class.included_modules
=> [Kernel]

Moreover, I found that require is private method of self:

irb(main):037:0> self.private_methods
=> [... "require", ...]

Same way, I can’t use self.attr_accessor:

irb(main):051:0> class X
irb(main):052:1> self.attr_accessor(:ssss)
irb(main):053:1> end
NoMethodError: private method `attr_accessor' called for X:Class
from (irb):52
from /usr/lib/ruby/1.8/date.rb:437

How does it happend? Can anybody clarify that questions?

  • 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-02T20:06:25+00:00Added an answer on June 2, 2026 at 8:06 pm

    Check the following simple example:

    class Person
      def initialize(age)
        @age = age
      end
    
      def compare_to(other)
        # we're calling a protected method on the other instance of the current class
        age <=> other.age
      end
    
      # it will not work if we use 'private' here
      protected
    
      def age
        @age
      end
    end
    

    In ruby we have implicit and explicit methods receiver, check the next code snippet:

    class Foo
      def a; end
    
      # call 'a' with explicit 'self' as receiver
      def b; self.a; end
    
      # call 'a' with implicit 'self' as receiver
      def c; a; end
    end
    

    Basically in ruby if a method is private it can be called only on implicit receiver (without self keyword). In your example require is a private method defined the Kernel module and it can be called only on the implicit subject.

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

Sidebar

Related Questions

In Ruby I can use result << (yield element) and everything works, but if
is there some ruby code I can use to install a gem from a
Normally to use Ruby libraries from command line I can do something like: ruby
In Ruby 1.9, I can use its class variable like the following: class Sample
I'm trying to use Java Opencl from within jruby, but am encountering a problem
I want to be able to have one ruby file that can require all
I am asking this for Ruby, but I guess this principle can be applied
I am using ruby 1.9.2-p290 and RubyMine. And i try to use Matrix (require
I'm attempting to use Mongoid from a plain Ruby script (not via Rails or
In Ruby you can write a rescue at the end of an assignment to

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.