From: pat eyler Date: 2006-04-11T00:40:22+09:00 Subject: Re: Quick syntax question On 4/10/06, Austin Ziegler wrote: > On 4/10/06, Gregory Seidman wrote: > > Consider the following three class definitions: > > > > class Foo > > def self.bar > > @@bar > > end > > def self.bar=(val) > > @@bar = val > > end > > end > > > > class Foo > > class << self > > def bar > > @@bar > > end > > def bar=(val) > > @@bar = val > > end > > end > > end > > [different third class deleted] > > Am I correct in believing that they are equivalent? If not, how do they > > differ? > > They are not equivalent. The first two are the same, but the third > will be accessing @bar, not @@bar. (Try it in IRB and you'll see.) > Interestingly though, the the sexps representing the AST for the first two classes are pretty different looking: [[:class, :Example, :Object, [:defn, :example, [:scope, [:block, [:args], [:defs, [:self], :bar, [:scope, [:block, [:args], [:cvar, :@@bar]]]], [:defs, [:self], :bar=, [:scope, [:block, [:args, :val], [:cvasgn, :@@bar, [:lvar, :val]]]]]]]]] vs. [[:class, :Example, :Object, [:defn, :example, [:scope, [:block, [:args], [:sclass, [:self], [:scope, [:block, [:defn, :bar, [:scope, [:block, [:args], [:cvar, :@@bar]]]], [:defn, :bar=, [:scope, [:block, [:args, :val], [:cvasgn, :@@bar, [:lvar, :val]]]]]]]]]]]]] > -austin > -- > Austin Ziegler * halostatue@gmail.com > * Alternate: austin@halostatue.ca > -- thanks, -pate -------------------------