How To Call An Objects Private Methods In Ruby

Posted by Weston Ganger on March 05, 2016

Sometimes you need to run an objects private method from the console or something.

For example your model may look something like this:

class Post < ActiveRecord::Base


  def set_initial_values
    # do work

  def update_title(new_url = false)
    # do work

Fortunately it can be done using the send method


# or with arguments

@post.send(:update_title, true)

Related External Links:

Posted in Rails and Tagged with rails ruby 

Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts