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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T08:31:44+00:00 2026-05-12T08:31:44+00:00

Coming from a long history of C-style syntax and now trying to learn Ruby

  • 0

Coming from a long history of C-style syntax and now trying to learn Ruby (on Rails), I’ve been having my share of issues with its idioms and such, but today I hit one I didn’t expect to have a problem with and I can’t see whatever it is that must be right in front of my face.

I have a Binary class that includes a private method to derive a URI value from a path value (uri and path are attributes of the class). I’m calling self.get_uri_from_path() from within Binary.upload(), but I get:

Attempt to call private method

A snippet of the model looks like this:

class Binary < ActiveRecord::Base
  has_one :image

  def upload( uploaded_file, save = false )
    save_as = File.join( self.get_bin_root(), '_tmp', uploaded_file.original_path )

    # write the file to a temporary directory
    # set a few object properties

    self.path   = save_as.sub( Rails.root.to_s + '/', '' )
    self.uri    = self.get_uri_from_path()
  end

  private

  def get_uri_from_path
    return self.path.sub( 'public', '' )
  end
end

Am I making the call incorrectly? Am I missing something else that’s even more fundamental? The only place that Binary.get_uri_from_path() is being called from – at the moment – is Binary.upload(). I’d expect to be able to call a private method from within the same class unless Ruby does something markedly different from other languages I’ve used.

Thanks.

  • 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-12T08:31:45+00:00Added an answer on May 12, 2026 at 8:31 am

    Don’t do

    self.get_uri_from_path()
    

    do

    get_uri_from_path()
    

    Because…

      class AccessPrivate
        def a
        end
        private :a # a is private method
    
        def accessing_private
          a              # sure! 
          self.a         # nope! private methods cannot be called with an explicit receiver at all, even if that receiver is "self"
          other_object.a # nope, a is private, you can't get it (but if it was protected, you could!)
        end
      end
    

    via

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

Sidebar

Related Questions

Coming from java/groovy/grails we are currently moving to rails. We have been having an
I have been using Python for about a year now, coming from a mostly
Coming from web development I have been trying to get familiar with compiled programming,
In trying to get up to speed with C++ (coming from a long experience
Coming from C/C++ a long time ago I still have a habit of ensuring
Ok, I'm coming from vb.net to c++. Im trying to use vectors in a
I am trying to implement a Queue in C. Coming from Java and other
I'm having a 'mare trying to get some simple data from my MySQL database.
I keep finding both on here and Google people having troubles going from long
Possible Duplicate: Why does C++ compilation take so long? Coming from C# background, I

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.