Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keyword arguments in [] operators #3918

Closed
ezrast opened this issue Jan 20, 2017 · 4 comments
Closed

Keyword arguments in [] operators #3918

ezrast opened this issue Jan 20, 2017 · 4 comments

Comments

@ezrast
Copy link

ezrast commented Jan 20, 2017

Keyword arguments can be defined for the [] operator but not used:

class Foo
  def [](**kwargs)
    puts "kwargs: #{kwargs}"
  end
end

Foo.new[]            # Works as expected; prints "kwargs: {}"
Foo.new[a: 1, b: 2]  # Syntax error: expecting token 'CONST', not '1'

This syntax works in Ruby.

@asterite asterite added this to the Next milestone Jan 20, 2017
@asterite
Copy link
Member

Good catch, thank you! To parse those arguments the parser was using some old logic that didn't take named args into account.

@ezrast
Copy link
Author

ezrast commented Feb 5, 2017

Appreciate the fix, but the nodes aren't getting passed into macros properly:

macro say(arg)
    puts "{{arg}}"
end

say(foo[])           # => foo[]
say(foo[:bar])       # => foo[:bar]
say(foo[bar: :baz])  # => foo[]

@luislavena
Copy link
Contributor

@ezrast looks to me a separate issue, macros behave differently. Please report a new one for this specific case.

Thank you.

@ezrast
Copy link
Author

ezrast commented Feb 5, 2017

Aye aye, created #4004 for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants