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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:11:47+00:00 2026-06-04T18:11:47+00:00

Ruby as an Object Oriented Language. What that means is whatever message I send,

  • 0

Ruby as an Object Oriented Language. What that means is whatever message I send, I strictly send it on some object/instance of class.

Example:

 class Test
   def test1
    puts "I am in test1. A public method"
    self.test2
   end

   def test2
    puts "I am in test2. A public Method"
   end
 end

makes sense I call method test2 on self object

But I cannot do this

  class Test
   def test1
    puts "I am in test1. A public method"
    self.test2 # Don't work
    test2 # works. (where is the object that I am calling this method on?)
   end

   private
   def test2
    puts "I am in test2. A private Method"
   end
 end

When test2 is public method I can call it on self (fair enough, a method sent to self object). But when test2 is private method I cannot call it on self. So where is the object that I am sending method on?

  • 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-04T18:11:49+00:00Added an answer on June 4, 2026 at 6:11 pm

    The Problem

    In Ruby, private methods can’t be called directly with an explicit receiver; self doesn’t get any special treatment here. By definition, when you call self.some_method you are specifying self as the explicit receiver, so Ruby says “No!”

    The Solution

    Ruby has rules for its method lookups. There may be a more canonical source for the rules (other than going to the Ruby source), but this blog post lays out the rules right at the top:

    1) Methods defined in the object’s singleton class (i.e. the object itself)
    2) Modules mixed into the singleton class in reverse order of inclusion
    3) Methods defined by the object’s class
    4) Modules included into the object’s class in reverse order of inclusion
    5) Methods defined by the object’s superclass, i.e. inherited methods
    

    In other words, private methods are first looked up in self without requiring (or allowing) an explicit receiver.

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

Sidebar

Related Questions

So, I'm curious as to how Ruby is a fully object oriented language. I
Ruby is fully object oriented language . In ruby, everything is an object &
Please recommend some material about implementing Object-Oriented Databases for dynamic languages (interested in Ruby).
Why do this Ruby object both a to_s and inspect methods that appear to
Ruby defines #clone in Object . To my suprise, some classes raise Exceptions when
Ruby's unit testing framework executes unit tests even though nobody creates unit test object.
When sent a message, a Ruby object searches to see whether it has a
Normally, I might get the metaclass for a particular instance of a Ruby object
I am learning Object Oriented Programming, but I am confused about abstract class and
Problem Normal objects serialize to something like: --- !ruby/object {}\n\n whereas Mail::Message serialize 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.