On Wed, Oct 31, 2012 at 4:28 PM, Eliezer Croitoru <eliezer / ngtech.co.il>wrote:

> I am wondering who will use such if condition?
> it's not even a if condition at all.
> why would you declare the variable in the if statement?
>

That's a good question.  Generally assignments in conditions of control
flow statements only make sense for loops because that sometimes allows to
avoid redundant code:

# option 1: redundant code
line = io.gets

while line
  puts line
  line = io.gets
end

# option 2: no redundant code and shorter
while line = io.gets
  puts line
end

# even better
io.each_line do |line|
  puts line
end

With an "if" it's never necessary.  And I do not think it makes a
difference performance wise.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/