1

In my application has status array which is something like this

 status = ['success','failure','warning']

For example, lambda to process status array like this

 print_status = lambda { |stat| puts stat }

When I'm trying to pass lambda on status's each method, I got an error which says "ArugmentError: wrong number of arguments (1 for 0)"

 status.each(print_status) 

any one help me to fix this issue.

1 Answer 1

2

This issue happen due to block and proc mismatch. In your status each method expects block not proc. Ideal solution to convert proc to block is that "&"

 status.each(&print_status)

Hope this code may help you to solve your issue

Sign up to request clarification or add additional context in comments.

3 Comments

And if you do not want to convert it to a proc a slightly uglier syntax would be status.each{|stat|print_status.call(stat)}
This is the solution, you save my time :), thanks Veerasekar. hirolau thanks for your suggestion.
@main_ka Is it useful?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.