Actions
Bug #10024
closedArray injection of ternary operators injects boolean rather than ternary result
Bug #10024:
Array injection of ternary operators injects boolean rather than ternary result
Description
The following code:
a = []
a << ''.blank? ? 'blank' : 'not blank'
puts a
renders [true].
I would expect it to render ['blank']
If I wrap it in parenthesis it does work.
a = []
a << ( ''.blank? ? 'blank' : 'not blank' )
puts a # ['blank']
it seems like the logic internally is perceiving this function as:
(a << ''.blank?) ? 'blank' : 'not blank'
Which seems illogical.
Updated by pducks32 (Patrick Metcalfe) over 11 years ago
The #<< has a higher precedence than the ternery operator. Using #<<= seems to make it work just fine.
Updated by nobu (Nobuyoshi Nakada) over 11 years ago
- Description updated (diff)
- Status changed from Open to Rejected
<< and >> are shift operators primarily, and have higher precedence.
Actions