[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Facets error while using Time.parse

meruby

7/27/2007 5:39:00 PM

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

6 Answers

Trans

7/27/2007 7:34:00 PM

0



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.


meruby

7/27/2007 7:35:00 PM

0

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, 12:38 pm, "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


Ezra Zygmuntowicz

7/27/2007 8:55:00 PM

0


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.

Cheers-
-- Ezra Zygmuntowicz
-- Founder & Ruby Hacker
-- ez@engineyard.com
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)



Trans

7/27/2007 9:51:00 PM

0



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.


Daniel DeLorme

7/28/2007 12:39:00 PM

0

Trans wrote:
>> [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

Trans

7/28/2007 1:27:00 PM

0



On Jul 28, 5:38 am, Daniel DeLorme <dan...@dan42.com> wrote:
> Trans wrote:
> >> [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.