Bug #1303: A name considered a local variable on RHS of an assignment that defines it
http://redmine.ruby-lang.org/issues/show/1303

Author: Tomas Matousek
Status: Open, Priority: Low
Category: core, Target version: 1.9.1
ruby -v: ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-mswin32]

The following script defines a method "f" and then a variable "f" by an assignment [1]. There is a reference to "f" on RHS of the assignment. The parser treats this reference as a reference to the local variable "f", not to the method "f", since it has already seen an assignemnt to "f". However, one might expect that within the RHS of an assignment the local variable defined by the assignment should not be visible yet (and indeed its value is nil). The following code should therefore print 123 and and not nil.

def f
  123
end

f = f.inspect    # [1]

puts f


----------------------------------------
http://redmine.ruby-lang.org