From: Yossef Mendelssohn Date: 2007-09-25T01:53:52+09:00 Subject: Re: best way to 'hide' a method when method_missing is in town On Sep 24, 10:42 am, Yossef Mendelssohn wrote: > On Sep 24, 9:53 am, vinbarnes wrote: > > > On Sep 24, 9:33 am, Paul Brannan wrote: > > > > There probably is a better solution to your problem, but it depends on > > > *why* you desire this behavior. > > > I'm trying to hide attributes in a Rails model. ActiveRecord::Base has > > method_missing defined to build getter/setter methods for attributes > > on the fly. But the problem is more general in nature as I described. > > > Kevin > > As you said, this problem can be solved with method_missing in Sub. > > class Sub > def method_missing(method, *args) > if private_methods.include?(method.to_s) > send(method, *args) > else > puts "#{method} caught in sub" > end > end > end > > This isn't a solution for your problem, but a comment on the > (possible?) root of it: IMO, method_missing shouldn't fire on private/ > protected method calls. My opinion goes further, that calling a > private or protected method shouldn't raise the same exception as > calling a method that doesn't exist. If for some reason one wants to > track attempted access to private methods, rescuing NoMethodError and > checking text is somewhat unsavory. It would be nicer to rescue > MethodAccessLevelError (or something with an even better name), which > could be related to NoMethodError based on use cases (right now, I see > them as children of the same parent). > > -- > -yossef > > -- > -yossef Wow, excellent double-sig there. To balance it all out, I won't put a sig on this.