Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4628

Is assignment in a conditional clause good ruby style?

$
0
0

In order to write more concisely, rather than do this:

test_value = method_call_that_might_return_nil()if test_value  do_something_with test_valueend

I've been assigning in the conditional:

if test_value = method_call_that_might_return_nil()  do_something_with test_valueend

Is this bad style? The still-more-concise syntax:

do_something_with test_value if test_value = method_call_that_might_return_nil()

is not allowed, as discussed in another SO question, and will remain that way in 1.9, according to Matz (http://redmine.ruby-lang.org/issues/show/1141).

Given the possible confusion of assignment and comparison, does this make it too hard to read the code?


Viewing all articles
Browse latest Browse all 4628

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>