Giter Site home page Giter Site logo

:if condition fails with "wrong number of arguments (1 for 0) (ArgumentError)" when lambda doesn't accept an argument about representable HOT 6 CLOSED

trailblazer avatar trailblazer commented on June 28, 2024
:if condition fails with "wrong number of arguments (1 for 0) (ArgumentError)" when lambda doesn't accept an argument

from representable.

Comments (6)

apotonick avatar apotonick commented on June 28, 2024

Sorry, this issue didn't come through via email - I found it by accident! 😁

Yes, this is documented in CHANGES and I also blogged about it (uhm.... probably).

As you already guessed, the "problem" is uber, which now handles all the dynamic options (like if: lambda { .. }. This breaking change was deliberate. Apologies for the breakage, though, but I had to cleanse the options - now they're all executed with the same mechanism.

You can fix that by ignoring the args, as in

if: lambda { |*| beers? }

Your suggestion to check arity is clever, however I decided not to do that a while ago as it adds complexity and still doesn't catch all the gotchas.

Is the |*| OK for you?

from representable.

brentsnook avatar brentsnook commented on June 28, 2024

My 5 cents - I'd allow blocks that have no parameters because I think that having to capture them when you don't need them just adds noise. I prefer handling that problem even if it adds complexity rather than let clients of uber/representative have to handle it. In that case I'd either handle the arity mismatch if possible or take the opportunity to fail in a more friendly way in order to make it easier for people to troubleshoot. It's also a breaking change (as we found out) - I'm not sure if you're following semantic versioning but I'd expect the major version to bump with a change like this.

These are just suggestions though, we've already worked around it as you suggested :)

from representable.

apotonick avatar apotonick commented on June 28, 2024

Hmm, yeah, a simple arity == 0 would actually do the trick. You're probably right, I might add it to uber.

I totally see your point on being "user-friendly" - however, this is a double-edged sword. Some projects completely went the wrong way in the last decade, providing "user-friendliness" to a degree where the internal magic, guessing and complexity outweighs the code use.

It's a pain in the ass to get rid of that madness now by deprecating all former forms. I don't want that in my gems and often explicit code is better understandable than magic methods that expose different APIs.

I try to but don't follow semantic versioning because I would be releasing a major version every two weeks. Most of my changes don't break existing code, though!

About semantic versioning: From my experience I can tell you that there should either be a fourth level (1.2.3.4), where 1.2 to 1.3 means internal (correction: semi-public) API has changed, or people should accept major number like 14.1.0. It is impossible to follow semantic versioning if your gem is going an aggressively innovative path.

from representable.

apotonick avatar apotonick commented on June 28, 2024

Here's the line from uber that executes the :if block: https://github.com/apotonick/uber/blob/master/lib/uber/options.rb#L77 It's so beautiful without any if..else 🌻 😏

from representable.

jan avatar jan commented on June 28, 2024

Also, you could update the readme, under available options and conditions. Adding |*| really isn't a problem, but finding out what needs to be done was for me.

from representable.

apotonick avatar apotonick commented on June 28, 2024

Thanks @jan - that's what pull requests are for 💋

from representable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.