> I've tried to not comment on this, but I'm failing, and I'll try real
> hard not to rehash well-known examples, issues, and languages.
>
> Instead, would it be more Ruby-ish to monkeypatch the Object class: e.g.,

> class Object
>   def initialized?
>     return defined? self and !self.nil
>   end
> end
> 
> Or some more user-friendly name, capturing the logical state you want
> to test on.
> 
> Unfortunately, that's not quite legal Ruby, and I haven't thought
> through the issues around it.  But the idea of providing a more
> readable check for a common idiom is a reasonable approach.

Uh, no.

1) "defined?" is special syntax, like "def" and "alias," that can't be
duplicated/extended in this way.  At best, you could do something with
the corresponding symbols (or even strings)--a la def_method-- but it
would be a cluttered nightmare.

2) The issue isn't the syntax, it's the semantics.  Having a "cleaner"
way to test (which this wouldn't be) isn't the issue.  Where the test is
appropriate, defined? is perfectly acceptable.

3) Even if all of the above weren't the case, "and !self.nil?" (assuming
you just forgot the "?") in a global monkeypatch is a code smell all its
own.  It will return true (and thus have no effect) everywhere but on
the singleton instance of NilClass.  It should be omitted for methods
such as this and they should, if needed, be overridden in NilClass.



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to