ruby - Scope of private, protected, and public -
within ruby class definition, scopes of private keyword in following scenarios:
class foo def bar_public puts "public" end private def bar_private puts "private" end def bar_public_2 puts "another public" end end
does private act on bar_private? or on bar_public_2 well?
in case both bar_private
, bar_public_2
private.
that because both methods "within scope" of private
keyword.
> f = foo.new #<foo:0xf1c770> > foo.new.bar_private nomethoderror: private method 'bar_private' called #<foo:0xf1c770> > foo.new.bar_public_2 nomethoderror: private method 'bar_public_2' called #<foo:0xf1c770>
either way, best way answer question open irb , try out ;-)
Comments
Post a Comment