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

Behavior of calling method with a hash varaible #5944

Closed
bamchoh opened this issue Mar 3, 2023 · 3 comments
Closed

Behavior of calling method with a hash varaible #5944

bamchoh opened this issue Mar 3, 2023 · 3 comments

Comments

@bamchoh
Copy link
Contributor

bamchoh commented Mar 3, 2023

Excuse me, I'd like to know if this is a specification for mruby or not.

When I executed below code, mruby raises exception.

Code:

def foo(bar)
    p bar
end

foo :var1 => :a

Output:

trace (most recent call last):
        [1] ..\..\scripts\test2.rb:5
..\..\scripts\test2.rb:1:in foo: wrong number of arguments (given 1, expected 1) (ArgumentError)

However, in ruby 3.2.0, it works

Output (ruby 3.2.0):

{"var1"=>"a"}

Is this behavior mruby's specification?

@matz
Copy link
Member

matz commented Mar 3, 2023

It's a bug. But I recommend wrapping hash arguments with braces, e.g. foo({:var1=>:a}), to disambiguate with keyword arguments.

@bamchoh
Copy link
Contributor Author

bamchoh commented Mar 3, 2023

Thank you for response. I understood my code is ambiguate and revised my code with your suggestion, then it works fine. Thank you very much :)

@bamchoh bamchoh closed this as completed Mar 3, 2023
@matz
Copy link
Member

matz commented Mar 4, 2023

It's still a bug to be fixed.

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

No branches or pull requests

2 participants