Trans
7/27/2007 9:51:00 PM
On Jul 27, 1:55 pm, Ezra Zygmuntowicz <ezmob...@gmail.com> wrote:
> On Jul 27, 2007, at 12:34 PM, Trans wrote:
>
>
>
>
>
> > On Jul 27, 10:40 am, "mer...@gmail.com" <mer...@gmail.com> wrote:
> >> I have install latest facets using gem. I am having this issue with
> >> Time.parse with facets. Any ideas?
>
> >> [spatel@taamserver ~]$ ruby --version
> >> ruby 1.8.6 (2007-06-07 patchlevel 36) [i686-linux]
>
> >> Everything is fine here:
>
> >> [spatel@taamserver ~]$ cat x1.rb
> >> #require 'facets'
> >> p Time.parse("3:40:40")
> >> p Time.parse('4:41:41')
> >> p Time.parse('5:42:42')
> >> [spatel@taamserver ~]$ ruby x1.rb
> >> Fri Jul 27 03:40:40 -0500 2007
> >> Fri Jul 27 04:41:41 -0500 2007
> >> Fri Jul 27 05:42:42 -0500 2007
>
> >> Same program with first line uncommented
>
> >> [spatel@taamserver ~]$ cat x1.rb
> >> require 'facets'
> >> p Time.parse("3:40:40")
> >> p Time.parse('4:41:41')
> >> p Time.parse('5:42:42')
> >> [spatel@taamserver ~]$ ruby x1.rb
> >> Fri Jul 27 03:40:40 -0500 2007
> >> Fri Jul 27 13:24:55 -0500 2007
> >> Fri Jul 27 13:24:55 -0500 2007
>
> > Want to see the culprit? Would you believe I tracked it to this:
>
> > class Symbol
> > # Same functionality as before, just a touch more efficient.
>
> > def to_s
> > @to_s || (@to_s = id2name)
> > end
> > end
>
> > I'm not sure how exactly that could break anything. But somehow it
> > does. Anyone?
>
> > A quick fix, remark out the line in lib/facets.rb (in facets' gem
> > dir):
>
> > #require 'facets/core/symbol/to_s'
>
> > T.
>
> Trans-
>
> I ran into this same thing, I had defined the same Symbol#to_s in
> merb. ActifveRecord was dropping created_at and updated_at attributes
> after the first time you would access them.
>
> Turns out it was some code deep in the Date stdlib that does some
> weird concatenating of symbols that was not compatible with
> Symbol#to_s as you have it defined. I had to remove it from my
> library because it caused very hard to track down bugs.
Thanks Ezra. It's gone now. I always felt a little off about that
method, but I could never see any reason not to have it. I benchmarked
and it did make symbol to_s slightly faster. Oh well I guess.
I can't make sense of it either, trying:
class Symbol
def to_s
@_to_s ||= id2name
puts "%10s %10s %10s %10s" % [inspect, id2name.inspect,
@_to_s.inspect, (id2name == @_to_s) ]
@_to_s
#id2name
end
end
Gives me this nutty result:
:_comp= "_comp=" "_comp=" true
:hour= "hour=" "hour=" true
:min= "min=" "min=" true
:sec= "sec=" "sec=" true
:_comp "_comp" "_comp" true
:zone "zone" "zone" true
:_comp "_comp" "_comp" true
:sec "sec" "sec" true
:hour "hour" "hour" true
:min "min" "min" true
Fri Jul 27 03:40:40 -0700 2007
:_comp= "_comp=" "_comp" false
:hour= "hour=" "hour" false
:min= "min=" "min" false
:sec= "sec=" "sec" false
:_comp "_comp" "_comp" true
:zone "zone" "zone" true
Fri Jul 27 14:45:18 -0700 2007
:_comp= "_comp=" "_comp" false
:hour= "hour=" "hour" false
:min= "min=" "min" false
:sec= "sec=" "sec" false
:_comp "_comp" "_comp" true
:zone "zone" "zone" true
Fri Jul 27 14:45:18 -0700 2007
But if I unremark the last line, they all come up true.
My guess is that their's deeper problem in Ruby's time/data libs that
needs to be fixed.
T.