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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:04:18+00:00 2026-06-05T14:04:18+00:00

The following code prints NoMethodError . I don’t understand the reason . Though the

  • 0

The following code prints NoMethodError. I don’t understand the reason . Though the method i am calling is private but i am calling it from within the class.Can’t a class var access it’s private variable/function ?. I could do this in Java.

class Tester
 private
   def func_pri
     puts("From a private function")
   end

 protected 
  def func_prot
    puts("From a protected function")
  end

 public
  def func_pub
     puts("From a public function")
  end

 public
  def caller(object)
    object.func_pub
    object.func_pri # This statement causes error
    object.func_prot
  end
 end

 o = Tester.new
 o.caller(o)
  • 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-05T14:04:20+00:00Added an answer on June 5, 2026 at 2:04 pm

    You cannot call private methods on an object, not even on self. Remove the object. part, then the call will go on self.

    If you do want to call a private method, you can always use object.send(:func_pri).

    Ruby is quite different than languages like Java in these terms. For more information, you might want to take a look at http://www.ruby-doc.org/docs/ProgrammingRuby/, chapter ‘Classes, Objects, and Variables’, section ‘Access Control’

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

Sidebar

Related Questions

The following code prints null once. class MyClass { private static MyClass myClass =
The following code, prints out Derived Base Base But I need every Derived object
The following code prints nothing CHECK_INCLUDE_FILE_CXX(glog/logging.h GLOG_INCLUDE) IF(GLOG_INCLUDE) MESSAGE(YY) ENDIF(GLOG_INCLUDE) But I have the
The following code prints the desired output but it prints garbage at the end
The following code prints: generic overload But what I wanted is that the overload
For some reason when I run the following code the program prints out JDN4
The following code prints [B@40545a60,[B@40545a60abc exp But I want to print abc , so
The following code prints out 10 . How can I make it print out
The following code prints (when invoking MyMethod): 0 0 0 1 I would expect
For example the following code prints { key: 'b' } function myFunc(key, value) {

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.