Facets error while using Time.parse

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

On Jul 27, 10:40 am, “[email protected][email protected] wrote:

p Time.parse(“3:40:40”)
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.

When I commented following line from /usr/lib/ruby/gems/1.8/gems/
facets-1.8.54/lib/facets.rb

require ‘facets/core/symbol/to_s’, it works! strange.

On Jul 27, 2007, at 12:34 PM, Trans wrote:

Same program with first line uncommented

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.

Cheers-
– Ezra Z.
– Founder & Ruby Hacker
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

Trans wrote:

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 can’t reproduce it on my system but for this kind of stuff you should
use id2name.freeze, otherwise the value of @to_s might be modified. In
others words, it’s not the same functionality.

Daniel

On Jul 28, 5:38 am, Daniel DeLorme [email protected] wrote:

I can’t reproduce it on my system but for this kind of stuff you should
use id2name.freeze, otherwise the value of @to_s might be modified. In
others words, it’s not the same functionality.

Indeed. I use to have #freeze in there, but apparently that caused
it’s own set of problems (or maybe it was the same problems in a
different guise).

T.

On Jul 27, 1:55 pm, Ezra Z. [email protected] wrote:

[spatel@taamserver ~]$ ruby --version
Fri Jul 27 03:40:40 -0500 2007
[spatel@taamserver ~]$ ruby x1.rb
@to_s || (@to_s = id2name)

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.