From: Mark Hubbart Date: 2004-06-16T03:45:50+09:00 Subject: Re: undefine On Jun 15, 2004, at 10:19 AM, tony summerfelt wrote: > On Tue, 15 Jun 2004 14:55:05 +0900, you wrote: > >>> I did not advocate removing, a.k.a. undefining, >>> instance variable, > > it would be a local variable i'd be undefining, probably not an > instance variable (although i'd like that option also) I think the whole point here is that it isn't Ruby-ish to rely on a variable being defined or not. Ruby wassn't built to do things in that way; a couple examples in this thread show how variables are automagically defined when code is parsed. They aren't defined at runtime, they are defined at eval time. So basically, If you are translating code from Perl that undefines local variables, you will have to find a different way of doing it, due to the way Ruby was designed. I doubt that this is likely to change, because it's part of how Ruby was designed. If you know Ruby well, there is almost certainly a way to do it that is just as reasonable and sensical as the Perl way, but it would be sensical for Ruby. >>> for global variables, and removal method for local >>> variables make no sense at all. > > only if the logic you use makes the code smaller or more efficient... > > larry wall added it to perl for a reason, and i'm guessing that he > thought it would be handy :) It is very handy for Perl, I know :) I used to use it. But there are other ways of doing the same sort of thing. To translate the given code into Ruby, I would (assuming that Delta_DHMS() won't return nil) write 'next unless diff.nil?', then later, 'diff = nil'. If there's a chance that the method might return nil, you can always use the trick Sean posted elsewhere on this thread.