Last Updated: February 25, 2016
·
211
· derekhall77

Ruby privates

Even if you make a method private in ruby, you can access it via 'send'.

class Hi
  def pub_hello
    puts "public hello"
  end

  private
  def priv_hello
    puts "private hello"
  end
end
hi = Hi.new
hi.pub_hello
#public_hello
hi.priv_hello
#error
hi.send(:priv_hello)
#private hello