if
cannot be rewritten as:
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 Mon, Feb 20, 2012 at 10:26 PM, Eric C. < [email protected]> wrote:
value
end
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’}).
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.
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 R.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.