From: dblack@... Date: 2007-07-23T22:49:01+09:00 Subject: Re: How do you "undef_method" for a class method? ---2049402039-16785632-1185198538=:15339 Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-16785632-1185198538=:15339" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. ---2049402039-16785632-1185198538=:15339 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Mon, 23 Jul 2007, Dean Wampler wrote: > On 7/22/07, dblack@wobblini.net wrote: >>=20 >> Hi -- >>=20 >> On Mon, 23 Jul 2007, Xavier Noria wrote: >>=20 >> > 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) >>=20 >> You're doing too much work :-) See Robert D.'s answer: >> >> class << Foo >> remove_method :method >> end >>=20 >> 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 (?). By me they are :-) Sometimes you'll hear the singleton class of a Class object referred to as a metaclass. Then again, sometimes you'll hear singleton classes in general referred to as metaclasses. I'm happy with "singleton class", but we're all waiting for a pronouncement from Matz :-) David --=20 * 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) ---2049402039-16785632-1185198538=:15339-- ---2049402039-16785632-1185198538=:15339--