-
-
Notifications
You must be signed in to change notification settings - Fork 50
Closed
Description
Hi Markus,
I have a function that takes a named argument named return. The usual trick to capture it in modern Rubies (shorter and faster that looking into binding) is {return:}[:return].
Unfortunately, unparser simply prints what parser gave, so it turns a "local variable" named return into an actual return keyword.
require 'parser/current'
require 'unparser'
ast = Unparser.parse(<<~RUBY)
def foo(return:)
puts({return:}[:return])
end
RUBY
p ast
puts Unparser.unparse(ast)$ bundle exec /tmp/unparser.rb
s(:def, :foo,
s(:args,
s(:kwarg, :return)),
s(:send, nil, :puts,
s(:index,
s(:hash,
s(:pair,
s(:sym, :return),
s(:lvar, :return))),
s(:sym, :return))))
def foo(return:)
puts({ return: return }[:return])
end
Of course the generated file then fails to run properly.
As far as I'm concerned, this is not urgent: I used binding for this particular case.
Cheers!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels