Project

General

Profile

Actions

Feature #7432

closed

Explicit way to define local variable in scope

Added by prijutme4ty (Ilya Vorontsov) almost 12 years ago. Updated almost 12 years ago.

Status:
Rejected
Target version:
[ruby-core:50070]

Description

Imagine code such as this
def test_smth
result = nil
assert_nothing_raised { result = some_slow_calculation }
assert_equal expected_answer, result
end
Line result = nil means nothing more than our intention to simply bind variable result in scope of assertion block with outer local variable. In large methods it can be much heavier to find out this obscured intention.
It may be better to introduce a method (if it can be implemented) or a keyword which simply creates a local variable (probably with nil value just to mark its existence)

define_variable 'x' or (define_variable x if it's a keyword)

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0