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
Written by Derek Hall
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Related Tags
#ruby
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#