Has Ruby developed backward compatibility with the 2.1.3 release around if-else statements?

I recently upgraded to Ruby 2.1.3, and to my surprise, I started getting some syntax errors. The smallest instance of the problem can be seen here:

{blah: if true then :bleh end}

      

which in Ruby 2.1.2 produces:

 => {:blah=>:bleh}

      

while in 2.1.3 it gives:

SyntaxError: (irb):1: syntax error, unexpected modifier_if
{blah: if true then :bleh end}
         ^

      

A more realistic example would be:

{blah: bleh
 blih: if false
         blah
       elsif true
         bloh
       else
         bluh
       end}

      

(yes, I don't know how to write code like this, but I'm used to it in Haskell and I think it makes for very concise and readable code).

Did Ruby 2.1.3 break backward compatibility? If so, it must be a bug according to the rules of semantic versioning, right?

Or was it unknowingly I misused a parser bug that was fixed?

Is there some (other) way to write if-conditions as expressions?

+3


source to share


1 answer


the bug was reported on the ruby ​​forums. Stay on top of this link:

https://bugs.ruby-lang.org/issues/10279

as we can see:



immediately after the label, a new expression must start, cannot be a modifier

The correct way to do it in ruby ​​2.1.3 should be:

2.1.3 :006 > {blah: (if true then :bleh end)}
 => {:blah=>:bleh}

      

+3


source







All Articles