# Facets error while using Time.parse

**URL:** <https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583>\
**Category:** Ruby\
**Created:** [July 27, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583 "2007-07-27T19:41:28Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 7:41pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583/1 "2007-07-27T19:41:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 9:34pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583/2 "2007-07-27T21:34:43Z")

</div>

On Jul 27, 10:40 am, “removed\_email\_address@domain.invalid” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 9:36pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583/3 "2007-07-27T21:36:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 10:56pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583/4 "2007-07-27T22:56:57Z")

</div>

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  
– removed\_email\_address@domain.invalid  
– Engine Y., Serious Rails Hosting  
– (866) 518-YARD (9273)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 28, 2007, 2:39pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583/5 "2007-07-28T14:39:12Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 28, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583/6 "2007-07-28T15:28:16Z")

</div>

On Jul 28, 5:38 am, Daniel DeLorme [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [July 27, 2007, 11:53pm UTC](https://www.ruby-forum.com/t/facets-error-while-using-time-parse/110583/7 "2007-07-27T23:53:07Z")

</div>

On Jul 27, 1:55 pm, Ezra Z. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.
