1.9.2 syntax issues

I admit I still use 1.8.x more often than 1.9.x -- and I keep running across
little things that puzzle or annoy me.

Why is it that this statement:

  value

···

=

    if
block_given?

      yield
str

else

str.send(converter)

end

cannot be rewritten as:

  value = block_given? ? yield str : str.send(converter)

Just curious...

Hal

It seems to be getting parsed like this
value = block_given? ? yield(str : str.send(converter))

You can get around it with parens like this:
value = block_given? ? (yield str) : str.send(converter)

Or by using the if/then/else/end keywords
value = if block_given? then yield str else str.send(converter) end

···

On Sun, Feb 19, 2012 at 3:49 PM, Hal Fulton <rubyhacker@gmail.com> wrote:

I admit I still use 1.8.x more often than 1.9.x -- and I keep running
across
little things that puzzle or annoy me.

Why is it that this statement:

  value

    if
block_given?

      yield
str

else

str.send(converter)

end

cannot be rewritten as:

  value = block_given? ? yield str : str.send(converter)

Just curious...

Hal

Doesn't look like a 1.8 vs 1.9 issue:

% ruby -vwe 'def x str; value = block_given? ? yield str : str.send(converter); end'
ruby 1.8.7 (2010-01-10 patchlevel 249) [universal-darwin11.0]
-e:1: syntax error, unexpected tIDENTIFIER
def x str; value = block_given? ? yield str : str.send(converter); end
                                           ^

All versions of ruby that I test against want `yield(str)`.

···

On Feb 19, 2012, at 13:49 , Hal Fulton wrote:

I admit I still use 1.8.x more often than 1.9.x -- and I keep running across
little things that puzzle or annoy me.

Why is it that this statement:

  value =
    if block_given?
      yield str
    else
      str.send(converter)
    end

cannot be rewritten as:

  value = block_given? ? yield str : str.send(converter)

I admit I still use 1.8.x more often than 1.9.x -- and I keep running
across
little things that puzzle or annoy me.

Why is it that this statement:

value

if

block_given?
yield
str

else

str.send(converter)

end

cannot be rewritten as:

value = block_given? ? yield str : str.send(converter)

Just curious...

Hal

It seems to be getting parsed like this
value = block_given? ? yield(str : str.send(converter))

What syntactic sense does (str : str.send(converter)) make in Ruby? My
first thought was that it would think str is a symbol key, but that
doesn't seem to be a case (you can't write a hash as {foo : 'foo'}).

···

On Sun, Feb 19, 2012 at 4:08 PM, Josh Cheek <josh.cheek@gmail.com> wrote:

On Sun, Feb 19, 2012 at 3:49 PM, Hal Fulton <rubyhacker@gmail.com> wrote:

You can get around it with parens like this:
value = block_given? ? (yield str) : str.send(converter)

Or by using the if/then/else/end keywords
value = if block_given? then yield str else str.send(converter) end

Ruby is icky when it comes to parentheses sometimes. It also won't
parse "1 + f 2", and why, I still have no idea. (I've been told it's
got something to do with operator priority or correctly parsing "f
1+2"...)

It usually makes sense to imagine open-paren right after function
name, and close-paren always at the end of line or at higher-level
close-paren. (Eg. ary[func 5] - the brackets here are what I call
higher-level.)

-- Matma Rex

Well, you can write it as {foo: 'foo'}, so I suppose it could look like you
meant to write a hash but made a mistake. More likely, this is probably
just an edge case in the parser's abilities.

···

On Mon, Feb 20, 2012 at 10:26 PM, Eric Christopherson < echristopherson@gmail.com> wrote:

On Sun, Feb 19, 2012 at 4:08 PM, Josh Cheek <josh.cheek@gmail.com> wrote:
> On Sun, Feb 19, 2012 at 3:49 PM, Hal Fulton <rubyhacker@gmail.com> > wrote:
>>
>> I admit I still use 1.8.x more often than 1.9.x -- and I keep running
>> across
>> little things that puzzle or annoy me.
>>
>> Why is it that this statement:
>>
>> value
>> =
>> if
>> block_given?
>> yield
>> str
>>
>> else
>>
>> str.send(converter)
>>
>> end
>>
>> cannot be rewritten as:
>>
>> value = block_given? ? yield str : str.send(converter)
>>
>>
>> Just curious...
>>
>> Hal
>>
>
> It seems to be getting parsed like this
> value = block_given? ? yield(str : str.send(converter))

What syntactic sense does (str : str.send(converter)) make in Ruby? My
first thought was that it would think str is a symbol key, but that
doesn't seem to be a case (you can't write a hash as {foo : 'foo'}).