-
Notifications
You must be signed in to change notification settings - Fork 53
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
Add to_enum to the list of defined explicit conversions #46
Conversation
Rename for consistency and clarity vs. implicit_conversions_spec.rb.
Hmmm, it looks like requiring
That got me thinking about a different implementation that uses |
Insofar as one of the goals of this library is to have fun with use metaprogramming, this patch definitely furthers this goal. 😏 Specs are passing now, including on Ruby 1.9.3, which was failing before this patch. |
We need to be very careful here that there's no chance of interfering badly with any other places that |
This change to the specs more accurately reflects the implementation, which now delegates all of these methods to nil. This change also allows the specs to run (and pass) on Ruby 1.9 without any conditional logic.
@avdi Ah, I hadn’t considered how using In the mean time, I’ve rolled back to the previous implementation, that used Feel free to |
Most of these changes are no-brainer accepts. I'm still a little dubious about the central one though. I'm not sure how common use of I guess the central question is: given I have a NullObject standing in for My knee-jerk response to this is that if we have it, ...and sorry to be so difficult! |
I don’t think you’re being difficult at all. You’re asking the questions that a project maintainer should ask. As I mentioned above, I asked these very same questions to myself:
This may have been the wrong decision on my part. I don’t feel confident enough in the decision to really defend it and I’m growing dubious of the usefulness of this feature, so I’m pretty happy to close it at this point. I’ve already pull the other commits into my Thanks for considering this. |
I was curious if there were any other conversion methods defined on
nil
that were not being delegated inNaught::NullClassBuilder::Commands::DefineExplicitConversions
, so I ran the following command:Currently,
DefineExplicitConversions
defines all of these methods save for one:to_enum
. I’m not sure how useful this will be in practice, but it seems like the right thing to do, for the sake of completeness. And—who knows—maybe someone out there wants to use a null object to stand in for anEnumerator
. It’s not that crazy.Of course, if you try passing a block to any
Enumerable
method on the nullEnumerator
, it will fail with theNoMethodError
:I debated whether the null enumerator should be defined as
[].to_enum
or{}.to_enum
, so it would iterate zero times instead of raising an error, but ultimately settled onnil.to_enum
, mostly for consistency in both the specs and implementation.This patch does a few other things as well. It:
In case you’re curious, I use the following command to do that, which I keep as an alias: