Project

General

Profile

Actions

Bug #11528

closed

Possible parsing bug. Possibly just confusing.

Added by olleicua (Antha Auciello) over 8 years ago. Updated over 8 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:<unknown>]

Description

Not sure if this is intentional behavior but I found it confusing:

code:

def render(args)
  p args.to_a
end

print 'functionally (without parentheses): '
render "foobar".length\
        .to_s(2)\
        .split('')\
        .map do |d|
  {digit: d}
end

print 'functionally (with parentheses): '
render("foobar".length\
        .to_s(2)\
        .split('')\
        .map do |d|
         {digit: d}
       end)

print 'with an intermediate variable: '
data = "foobar".length\
        .to_s(2)\
        .split('')\
        .map do |d|
  {digit: d}
end
render data

output:

functionally (without parentheses): ["1", "1", "0"]
functionally (with parentheses): [{:digit=>"1"}, {:digit=>"1"}, {:digit=>"0"}]
with an intermediate variable: [{:digit=>"1"}, {:digit=>"1"}, {:digit=>"0"}]
Actions #1

Updated by olleicua (Antha Auciello) over 8 years ago

I'm realizing this is probably intentional: http://blog.plataformatec.com.br/2014/07/ruby-blocks-precedence/

It looks like I'm not allowed to close my own bug. Sorry for the distraction.

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 8 years ago

  • Description updated (diff)
  • Status changed from Open to Rejected
Actions

Also available in: Atom PDF

Like0
Like0Like0