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'}). > > 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