From: Colin Bartlett Date: 2012-07-09T11:11:35+09:00 Subject: Re: Can you call private methods with explicit receivers? On Thu, Jul 5, 2012 at 6:16 PM, Jingjing Duan wrote: > My understanding is the answer is no, you can't call private methods > with explicit receivers, even self. See > http://www.skorks.com/2010/04/ruby-access-control-are-private-and-protected-methods-only-a-guideline/ > > However, the following example seems to counter that. > > class A > def m2 > self.m1 = "hello" > self.m3 > end > > private > > def m1=(value) > @m1 = value > puts "assigning #{value} to @m1" > end > > def m3 > puts "inside m3" > end Picking up Bartosz DziewoƄski's reference to #send, also note this: A.new.m2 rescue puts $!.inspect A.new.m3 rescue puts $!.inspect A.new.send(:m3) rescue puts $!.inspect produces: assigning hello to @m1 #> #> inside m3