From: dblack@... Date: 2006-04-11T10:48:59+09:00 Subject: Re: Class Definition inside a method definition? ---2049402039-834061525-1144720136=:17837 Content-Type: MULTIPART/MIXED; BOUNDARY="-2049402039-834061525-1144720136=:17837" 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-834061525-1144720136=:17837 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE Hi -- On Tue, 11 Apr 2006, David Vallner wrote: > D=C5=88a Utorok 11. Apr=C3=ADl 2006 02:39 Bihal nap=C3=ADsal: >> Thanks David. I'm not sure you caught sight of the line of code I was >> worried about. I should have made it more clear. This one in particular >> >> sclass =3D class << self; self; end >> >> does use a class keyword and syntactic construct, it's just on a single >> line. >> >> Bihal > > Well, "class << self" isn't really a class definition, it's a change of s= cope > into an object's singleton class. It's still a class definition block -- it's just that the class is identified with the << obj construct rather than a simple constant name. The class keyword takes either form, but it's still basically doing the same thing. > It just looks a real awful lot like one ;P > Which might, or might not exist at the time, and in the latter case it > indeeds starts to exist. I'm also possibly very wrong, but I've been able= to > live with understanding this that way ;P > > Also, Pickaxe seems mildly wrong about the instance method definition bit= : > > irb(main):001:0> class Foo > irb(main):002:1> def bar > irb(main):003:2> def quux > irb(main):004:3> puts "Foo#quux" > irb(main):005:3> end > irb(main):006:2> end > irb(main):007:1> end > =3D> nil > irb(main):008:0> foo =3D Foo.new > =3D> # > irb(main):009:0> foo.quux > NoMethodError: undefined method `quux' for # > from (irb):9 > from :0 > irb(main):010:0> foo.bar > =3D> nil > irb(main):011:0> foo.quux > Foo#quux > =3D> nil > irb(main):012:0> Foo.new.quux > Foo#quux > =3D> nil > > Is that 1st ed. or 2nd ed. you're quoting? Might have changed between Rub= y 1.6 > and 1.8. It did change in that span. David --=20 David A. Black (dblack@wobblini.net) Ruby Power and Light, LLC (http://www.rubypowerandlight.com) "Ruby for Rails" coming in PDF April 15, and in paper May 5! http://www.manning.com/black ---2049402039-834061525-1144720136=:17837-- ---2049402039-834061525-1144720136=:17837--