From: Ryan Davis Date: 2011-01-27T06:49:13+09:00 Subject: Re: ruby treatment of method defs On Jan 26, 2011, at 12:33 , James Byrne wrote: > In the ruby language if I do this: > > def g=( value ) > @gval = value.to_s > end > > def g > @gval > end > > g = 12 > > Then g == 12, @gval == nil and g.class == Fixnum > > I realize that this has to do with the way Ruby processes undefined > identifiers at runtime. However, it strikes me that it is fundamentally > wrong to ignore an existing explicit method declaration within the > current scope in favour of creating a locally scoped variable instead. > This behaviour is counter-intuitive and the ugly work-around required > (self.g = 12) only accentuates how out of place it is. def x g = 12 end g= is "in scope" as you put it. Which should it be? local assignment or method call? require 'g' def x g = 12 end how about now? Does your answer change? If so, why?