Facets error while using Time.parse

M

meruby

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
 
T

Trans

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.
 
M

meruby

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.
 
E

Ezra Zygmuntowicz

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.

Cheers-
-- Ezra Zygmuntowicz
-- Founder & Ruby Hacker
-- (e-mail address removed)
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
 
T

Trans

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'

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.
 
D

Daniel DeLorme

Trans said:
[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 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
 
T

Trans

Trans said:
[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 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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,664
Latest member
RoseannBow

Latest Threads

Top