From: Simon Kitching Date: 2003-10-16T09:42:59+09:00 Subject: Re: General Ruby Programming questions On Thu, 2003-10-16 at 13:14, James Britt wrote: > Eric Hodel wrote: > > > Simon Kitching (simon@ecnetwork.co.nz) wrote: > ... > >>Is there any reason why Ruby allows private methods to be invoked like > >>this? (rather than provide a tidy alternative for problems like mine). > > > > > > I believe I'm giving a fairly accurate paraphrase of matz when I say > > that Ruby doesn't prevent you from writing sloppy code, it just makes it > > look ugly enough so that you don't do it. > > > > And if you really want to trap such calls you can override 'send': > > module SafeSend > alias evil_unsafe_send send > def send( m, *args ) > msg = "No sending of private messages!" > raise msg if self.private_methods.include? m.to_s > evil_unsafe_send( m, *args ) > end > end > > > class Foo > include SafeSend > # ... > end Hah! Consider my questions answered :-) I love the way Ruby can override default behaviours..... Regards, Simon