From: "Jesús Gabriel y Galán" Date: 2008-10-15T23:56:18+09:00 Subject: Re: Lame question about instance variable and attribute On Wed, Oct 15, 2008 at 4:44 PM, dkmd_nielsen wrote: > Assuming an attribute :field is defined, is there a processing > difference between using @field and self.field [within the defining > class?] Does the ruby interpretter take a different path in yielding > the value depending how it is referenced? I haven't notice anything. > I'm just curious if the interpretter takes extra steps when yielding > self.field. @field accessed the instance variable directly, while self.field calls the method "field" on self. So the paths are completely different: irb(main):001:0> require 'parse_tree' => true irb(main):027:0> class B irb(main):028:1> attr_reader :b irb(main):029:1> def test irb(main):030:2> @b irb(main):031:2> end irb(main):035:1> def test3 irb(main):036:2> self.b irb(main):037:2> end irb(main):038:1> end => nil irb(main):039:0> ParseTree.new.parse_tree_for_method(B, :test) => [:defn, :test, [:scope, [:block, [:args], [:ivar, :@b]]]] irb(main):040:0> ParseTree.new.parse_tree_for_method(B, :test3) => [:defn, :test3, [:scope, [:block, [:args], [:call, [:self], :b]]]] Jesus.