Within a Ruby class definition, what is the scopes of the private keyword in the 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 only act on bar_private? or on bar_public_2 as well?
In your case both
bar_privateandbar_public_2are private.That is because both methods are “within scope” of the
privatekeyword.Either way, the best way to answer you question is to open IRB and try it out 😉