From: Dean Wampler Date: 2007-07-23T22:34:56+09:00 Subject: Re: How do you "undef_method" for a class method? ------=_Part_95987_17305041.1185197689477 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable Content-Disposition: inline On 7/22/07, dblack@wobblini.net wrote: > > Hi -- > > On Mon, 23 Jul 2007, Xavier Noria wrote: > > > El Jul 22, 2007, a las 6:44 PM, Dean Wampler escribi=F3: > > > >> Module#undef_method and Module#remove_method work fine for instance > >> methods, > >> but if you specify a class method, your get an error that it doesn't > exist. > >> (I'm using ruby 1.8.6.) > > > > You need to get into the singleton class: > > > > (class << Foo; self; end).send(:remove_method, :method) > > You're doing too much work :-) See Robert D.'s answer: > > class << Foo > remove_method :method > end > > Once you're in the class definition body, you can just go ahead and do > things; you don't have to grab the class and address it > programmatically unless there's a specific reason. That did it. Thanks. It didn't occur to me to open the singleton class on a class itself, as opposed to opening the singleton class for an object. I assume that both are called singleton classes (?). dean David > > -- > * Books: > RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242) > RUBY FOR RAILS (http://www.manning.com/black) > * Ruby/Rails training > & consulting: Ruby Power and Light, LLC (http://www.rubypal.com) > --=20 Dean Wampler http://www.objectmentor.com http://www.aspectprogramming.com http://www.contract4j.org ------=_Part_95987_17305041.1185197689477--