On 28/03/2008, Edwin Pratomo <[EMAIL PROTECTED]> wrote:

>  class Time
>   def self.pst
>     begin
>       old_tz = ENV['TZ']
>       ENV['TZ'] = "US/Pacific"
>       t = Time.now

from this line, what if you're dissallowed to write Time.now? what if
there is an existed time already, say : 1.week.ago . Do you have any
ideas how to *get* that 1.week.ago.pst .... That's why I emphasized
the output result should exist as a Time object instance instead of
Time class method.

from high level, one might say it answered my question, but from its
code, I don't see it behaves as I want, it's not *get* an existed
variable, it's (I mean, "it" means that line) was hacking itself to be
a PST, or in another word, it still *sets* Time.

>       t.to_s # force localtime(3) call using this TZ
>       t
>     ensure
>       ENV['TZ'] = old_tz
>     end
>   end
>  end
>
>  p Time.pst # Fri Mar 28 01:47:32 -0700 2008
>  p Time.now # Fri Mar 28 15:47:32 +0700 2008

if it's all about setter I can just easily do this from a long time ago :

>> Time.now
=> Fri Mar 28 17:29:10 +0800 2008
>> Time.zone.now
=> Fri, 28 Mar 2008 02:29:15 PDT -07:00
>> exit

>  rgds,
>  Edwin.

-- 
blog: http://tinyurl.com/2bjgvn,
ruby: http://www.ruby-lang.org/id/about

I always thought Smalltalk would beat Java, I just didn't know it
would be called 'Ruby' when it did. -- Kent Beck.

Kirim email ke