Is this Ruby warning making sense?

Does anyone think if this the warning makes any sense?

irb(main):002:0> puts "abc" if (a=true)
(irb):2: warning: found = in conditional, should be ==
abc

I thought in ruby, everything is an expression, so a=true should return
true, and
if (true) is totally valid. Why does it give the warning?

Or is this a language design thing?

rubyrus wrote:

Does anyone think if this the warning makes any sense?

irb(main):002:0> puts "abc" if (a=true)
(irb):2: warning: found = in conditional, should be ==
abc

I thought in ruby, everything is an expression, so a=true should return
true, and
if (true) is totally valid. Why does it give the warning?

Or is this a language design thing?

Any construction literal (true in this case) will produce such a warning since its value is already known,

but:

b=true
puts "blah" if a=b

wont

lopex

Writing 'if (foo = "bar")' instead of 'if (foo == "bar")' is a classic
error that has bitten many programmers, since it can be difficult while
quickly skimming the source code to determine whether the assignment
was intentional or simply a typo.

Since it's not technically invalid syntax, you just get a warning, but
I wouldn't recommend making heavy use of mixed assignment and test.

-Lennon