avdi/naught — pull request #46 by sferik (2014-01-07 03:02:48+00:00)
Title: Add to_enum to the list of defined explicit conversions

I was curious if there were any other conversion methods defined on `nil` that were not being delegated in `Naught::NullClassBuilder::Commands::DefineExplicitConversions`, so I ran the following command:

```ruby
> nil.methods.select{|method| method.to_s =~ /^to_\w+$/}
=> [:to_i, :to_f, :to_s, :to_a, :to_h, :to_r, :to_c, :to_enum]
```

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 an `Enumerator`. It’s not that crazy.

Of course, if you try passing a block to any `Enumerable` method on the null `Enumerator`, it will fail with the `NoMethodError`:

undefined method `each' for nil:NilClass

I debated whether the null enumerator should be defined as `[].to_enum` or `{}.to_enum`, so it would be iterable, but ultimately settled on `nil.to_enum`, mostly for consistency.

This patch does a few other things as well. It:

1. renames and improves the explicit conversions spec, to better match the new implementation,
2. runs the specs in random order to catch order-dependency bugs, and
3. makes the whitespace in this project more consistent. In case you’re curious, I use the following command to do that, which I keep as an [alias](https://github.com/sferik/dotfiles/blob/c3633182b77fb0023882810d9a524c8300293140/fish/functions/whitespace.fish):

find . -not \( -name .svn -prune -o -name .git -prune \) -type f -print0 | xargs -0 sed -i "" -E "s/[[:space:]]*\$//"