Ruby Quicktips Logo

Ruby Quicktips

Random Ruby and Rails tips.
This blog is dedicated to deliver short, interesting and practical tidbits of the Ruby language and Ruby on Rails framework. Read more...

Your submissions are more than welcome!
Jan 10 ’11

How to Call Private Methods On Objects

Calling private methods can for example be useful in unit testing to increase the code coverage.
Object#send gives you access to all methods of a particular object (even protected and private ones).

obj.send(:method [, args...])

In case send method has been overwritten, you can also use its aliased version __send__.

(Source: rubyloveinfo)

9 notes 0 comments (via rubyloveinfo)

  1. take-cheeze reblogged this from rubyquicktips
  2. rubyquicktips reblogged this from rubyloveinfo and added:
    object (even protected and private ones).
  3. rubyloveinfo posted this

Comments

You can use HTML tags for formatting. Wrap code in <code> tags and multiple lines of code in <pre><code> tags.

blog comments powered by Disqus