A little something for Giles et. al. who feel that private has no business in the Ruby language…

# Privacy? We don't need no stinkin' privacy!
module TSA
  def private
    # NOOP
  end

  def protected
    # NOOP
  end
end

class Class
  include TSA
end

class GropeMeBaby
  def shoes
    "No bombs here!"
  end

  private

  def knickers
    "I see London, I see france..."
  end
end

o = GropeMeBaby.new
o.shoes                         # => "No bombs here!"
o.knickers                      # => "I see London, I see france..."

Just include that somewhere early in your program and you won’t even have to think about it.

Published by Avdi Grimm

7 Comments

  1. That's what I love about Ruby — almost all the rules are in play.

    Reply
  2. Sorry to be off topic, but your “drop me a line” link isn't working. I would really like a way to download the entirety of your archives in my rss feed.

    Reply
    • What “drop me a line” link? And why do you want to download my archive?

      Reply
      • I was referring to the link in your resume page. I was looking to download your previous posts or at least the headers so that I could browse/search the topics easily in my RSS reader. At the time, I was trying to find an old post you had written with some difficulty. I honestly don't even remember what that was now, but still wouldn't mind being able to peruse your old posts more easily.

        Reply
        • Thanks for the heads-up on the resume page. For what it's worth, there's a contact form at http://avdi.org that works last I checked.

          For finding old posts I recommend the Google site-search box on the right-hand sidebar. I don't maintain any full-history RSS feeds, sorry.

          Reply
  3. I ran to this problem myself, but little differently.
    We had in our Article model (one of our juniors did it):

    class Article true, :active => true)
      # …
    protected
      # ..
    public
      def something
      end
     #…
    end

    Article.new.something

    => protected method called…

    What a 10 min-of-my-life-taking surprise 🙂

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *