When to use send and public_send methods in ruby?

Viewed 6345

send can be used to call public as well as private methods.

Example:

class Demo
  def public_method
    p "public_method" 
  end

  private

  def private_method
    p "private_method" 
  end
end

Demo.new.send(:private_method)
Demo.new.send(:public_method)

Then where and why to use public_send?

1 Answers
Related