Forum: Ruby-core [ruby-trunk - Bug #7734][Open] Post IF - undefined local variable

Posted by Sergey Ezhov (sergeyezhov)
on 2013-01-23 13:03
(Received via mailing list)
Issue #7734 has been reported by Sega100500 (Сергей Е).

----------------------------------------
Bug #7734: Post IF - undefined local variable
https://bugs.ruby-lang.org/issues/7734

Author: Sega100500 (Сергей Е)
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 1.9.3
ruby -v: 1.9.3p374


hash[:tree] = tree if (tree = _get_path_tree_array(params, path, deep + 
1)) && ! tree.empty?

# => undefined local variable or method `tree' for #<Content:0x92d96b0>

but

if (tree = _get_path_tree_array(params, path, deep + 1)) && ! 
tree.empty?
  hash[:tree] = tree
end

# => WORK FINE!


Content - is a: class Content < ActiveRecord::Base in Ruby on Rails 
3.2.11
Posted by matz (Yukihiro Matsumoto) (Guest)
on 2013-01-23 16:14
(Received via mailing list)
Issue #7734 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

The local variables are considered defined *after* the assignments, so 
that in above case, tree appears before the assignment is intentionally 
left undefined.

Matz.

----------------------------------------
Bug #7734: Post IF - undefined local variable
https://bugs.ruby-lang.org/issues/7734#change-35558

Author: Sega100500 (Сергей Е)
Status: Rejected
Priority: Normal
Assignee:
Category: core
Target version: 1.9.3
ruby -v: 1.9.3p374


hash[:tree] = tree if (tree = _get_path_tree_array(params, path, deep + 
1)) && ! tree.empty?

# => undefined local variable or method `tree' for #<Content:0x92d96b0>

but

if (tree = _get_path_tree_array(params, path, deep + 1)) && ! 
tree.empty?
  hash[:tree] = tree
end

# => WORK FINE!


Content - is a: class Content < ActiveRecord::Base in Ruby on Rails 
3.2.11
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.