Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > comments found in ObjectSpace

Reply
Thread Tools

comments found in ObjectSpace

 
 
Amarison
Guest
Posts: n/a
 
      10-11-2005
I ran the following code:

all = []

ObjectSpace.each_object do |obj|
all << obj
end

File.open('objectspace.txt','w') do |f|
f.puts all
end


and I was surprised to find comments in objectspace.txt. I was under the
impression that Ruby skips comments when parsing code.

Very strange behaviour... Anyone cares to explain? Thanks


 
Reply With Quote
 
 
 
 
wannes
Guest
Posts: n/a
 
      10-11-2005
On 11/10/05, Amarison <(E-Mail Removed)> wrote:
> I ran the following code:
> and I was surprised to find comments in objectspace.txt. I was under the
> impression that Ruby skips comments when parsing code.
> Very strange behaviour... Anyone cares to explain? Thanks


simple answer: those are no comments

try:

test =3D File.open("blah.txt",'w')
puts test
test.close

grtz,
wannes


 
Reply With Quote
 
 
 
 
Barson
Guest
Posts: n/a
 
      10-11-2005
I'm not sure what that code is supposed to do. Using my code, the text file
(around 152kb) that was produced contained a lot of comments, especially
from the Date class.


"wannes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On 11/10/05, Amarison <(E-Mail Removed)> wrote:
> I ran the following code:
> and I was surprised to find comments in objectspace.txt. I was under the
> impression that Ruby skips comments when parsing code.
> Very strange behaviour... Anyone cares to explain? Thanks


simple answer: those are no comments

try:

test = File.open("blah.txt",'w')
puts test
test.close

grtz,
wannes



 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      10-11-2005
Barson wrote:
> I'm not sure what that code is supposed to do. Using my code, the
> text file (around 152kb) that was produced contained a lot of
> comments, especially from the Date class.


These are no comments.

17:03:49 [source]: ruby -e 'ObjectSpace.each_object {|o| print o.class, "
", o.to_s.inspect, " ", o.inspect, "\n" if /^#/ =~ o.to_s }'
Binding "#<Binding:0x100e6dc8>" #<Binding:0x100e6dc8>
IO "#<IO:0x100ede18>" #<IO:0x100ede18>
IO "#<IO:0x100ede30>" #<IO:0x100ede30>
IO "#<IO:0x100ede48>" #<IO:0x100ede48>
Thread "#<Thread:0x100f5840>" #<Thread:0x100f5840 run>
ThreadGroup "#<ThreadGroup:0x100f5858>" #<ThreadGroup:0x100f5858>

17:03:54 [source]: ruby -r date -e 'ObjectSpace.each_object {|o| print
o.class, " ", o.to_s.inspect, " ", o.inspect, "\n" if /^#/ =~ o.to_s }'
File "#<File:0x100c6f08>" #<File:/usr/lib/ruby/1.8/rational.rb (closed)>
String "#<%s: %s,%s,%s>" "#<%s: %s,%s,%s>"
File "#<File:0x100e6ab0>" #<File:/usr/lib/ruby/1.8/date.rb (closed)>
Binding "#<Binding:0x100e6dc8>" #<Binding:0x100e6dc8>
IO "#<IO:0x100ede18>" #<IO:0x100ede18>
IO "#<IO:0x100ede30>" #<IO:0x100ede30>
IO "#<IO:0x100ede48>" #<IO:0x100ede48>
Thread "#<Thread:0x100f5840>" #<Thread:0x100f5840 run>
ThreadGroup "#<ThreadGroup:0x100f5858>" #<ThreadGroup:0x100f5858>
String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
String "#<Thread:0x100f5840 run>" "#<Thread:0x100f5840 run>"
String "#<Thread:0x100f5840>" "#<Thread:0x100f5840>"
String "#<Thread:0x100f5840>" "#<Thread:0x100f5840>"
MatchData "#" #<MatchData:0x10198bb8>
String "#<Thread:0x100f5840>" "#<Thread:0x100f5840>"
String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
MatchData "#" #<MatchData:0x10199c80>
String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
MatchData "#" #<MatchData:0x1019a208>
String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
String "#<File:/usr/lib/ruby/1.8/date.rb (closed)>"
"#<File:/usr/lib/ruby/1.8/date.rb (closed)>"
String "#<File:0x100e6ab0>" "#<File:0x100e6ab0>"
String "#<File:0x100e6ab0>" "#<File:0x100e6ab0>"
MatchData "#" #<MatchData:0x1019a328>
String "#<File:0x100e6ab0>" "#<File:0x100e6ab0>"
String "#<%s: %s,%s,%s>" "#<%s: %s,%s,%s>"
MatchData "#" #<MatchData:0x1019a538>
String "#<File:/usr/lib/ruby/1.8/rational.rb (closed)>"
"#<File:/usr/lib/ruby/1.8/rational.rb (closed)>"
String "#<File:0x100c6f08>" "#<File:0x100c6f08>"
String "#<File:0x100c6f08>" "#<File:0x100c6f08>"
MatchData "#" #<MatchData:0x1019a640>
String "#<File:0x100c6f08>" "#<File:0x100c6f08>"
String "#new_offset" "#new_offset"
String "#newof is deprecated; " "#newof is deprecated; "
String "#offset" "#offset"
String "#of is deprecated; " "#of is deprecated; "
String "#new_start" "#new_start"
String "#newsg is deprecated; " "#newsg is deprecated; "
String "#start" "#start"
String "#sg is deprecated; " "#sg is deprecated; "
String "# alias_method :format, :strftime\n" "# alias_method :format,
:strftime\n"
String "# $Id: format.rb,v 2.14 2004-11-06 10:58:40+09 tadf Exp $\n" "#
$Id: format.rb,v 2.14 2004-11-06 10:58:40+09 tadf Exp $\n"
String "# format.rb: Written by Tadayoshi Funaba 1999-2004\n" "#
format.rb: Written by Tadayoshi Funaba 1999-2004\n"
File "#<File:0x101c41a8>" #<File:/usr/lib/ruby/1.8/date/format.rb
(closed)>
17:03:55 [source]:

Kind regards

robert

 
Reply With Quote
 
Barson
Guest
Posts: n/a
 
      10-11-2005
Oh, yeah, I know that.

have a look at line 4525
or
in the text file, search for the following string without the double quotes:
"# without specifying the format"





"Robert Klemme" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Barson wrote:
> > I'm not sure what that code is supposed to do. Using my code, the
> > text file (around 152kb) that was produced contained a lot of
> > comments, especially from the Date class.

>
> These are no comments.
>
> 17:03:49 [source]: ruby -e 'ObjectSpace.each_object {|o| print o.class, "
> ", o.to_s.inspect, " ", o.inspect, "\n" if /^#/ =~ o.to_s }'
> Binding "#<Binding:0x100e6dc8>" #<Binding:0x100e6dc8>
> IO "#<IO:0x100ede18>" #<IO:0x100ede18>
> IO "#<IO:0x100ede30>" #<IO:0x100ede30>
> IO "#<IO:0x100ede48>" #<IO:0x100ede48>
> Thread "#<Thread:0x100f5840>" #<Thread:0x100f5840 run>
> ThreadGroup "#<ThreadGroup:0x100f5858>" #<ThreadGroup:0x100f5858>
>
> 17:03:54 [source]: ruby -r date -e 'ObjectSpace.each_object {|o| print
> o.class, " ", o.to_s.inspect, " ", o.inspect, "\n" if /^#/ =~ o.to_s }'
> File "#<File:0x100c6f08>" #<File:/usr/lib/ruby/1.8/rational.rb (closed)>
> String "#<%s: %s,%s,%s>" "#<%s: %s,%s,%s>"
> File "#<File:0x100e6ab0>" #<File:/usr/lib/ruby/1.8/date.rb (closed)>
> Binding "#<Binding:0x100e6dc8>" #<Binding:0x100e6dc8>
> IO "#<IO:0x100ede18>" #<IO:0x100ede18>
> IO "#<IO:0x100ede30>" #<IO:0x100ede30>
> IO "#<IO:0x100ede48>" #<IO:0x100ede48>
> Thread "#<Thread:0x100f5840>" #<Thread:0x100f5840 run>
> ThreadGroup "#<ThreadGroup:0x100f5858>" #<ThreadGroup:0x100f5858>
> String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
> String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
> String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
> String "#<ThreadGroup:0x100f5858>" "#<ThreadGroup:0x100f5858>"
> String "#<Thread:0x100f5840 run>" "#<Thread:0x100f5840 run>"
> String "#<Thread:0x100f5840>" "#<Thread:0x100f5840>"
> String "#<Thread:0x100f5840>" "#<Thread:0x100f5840>"
> MatchData "#" #<MatchData:0x10198bb8>
> String "#<Thread:0x100f5840>" "#<Thread:0x100f5840>"
> String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
> String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
> String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
> String "#<IO:0x100ede48>" "#<IO:0x100ede48>"
> String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
> String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
> String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
> String "#<IO:0x100ede30>" "#<IO:0x100ede30>"
> String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
> String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
> String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
> MatchData "#" #<MatchData:0x10199c80>
> String "#<IO:0x100ede18>" "#<IO:0x100ede18>"
> String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
> String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
> String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
> MatchData "#" #<MatchData:0x1019a208>
> String "#<Binding:0x100e6dc8>" "#<Binding:0x100e6dc8>"
> String "#<File:/usr/lib/ruby/1.8/date.rb (closed)>"
> "#<File:/usr/lib/ruby/1.8/date.rb (closed)>"
> String "#<File:0x100e6ab0>" "#<File:0x100e6ab0>"
> String "#<File:0x100e6ab0>" "#<File:0x100e6ab0>"
> MatchData "#" #<MatchData:0x1019a328>
> String "#<File:0x100e6ab0>" "#<File:0x100e6ab0>"
> String "#<%s: %s,%s,%s>" "#<%s: %s,%s,%s>"
> MatchData "#" #<MatchData:0x1019a538>
> String "#<File:/usr/lib/ruby/1.8/rational.rb (closed)>"
> "#<File:/usr/lib/ruby/1.8/rational.rb (closed)>"
> String "#<File:0x100c6f08>" "#<File:0x100c6f08>"
> String "#<File:0x100c6f08>" "#<File:0x100c6f08>"
> MatchData "#" #<MatchData:0x1019a640>
> String "#<File:0x100c6f08>" "#<File:0x100c6f08>"
> String "#new_offset" "#new_offset"
> String "#newof is deprecated; " "#newof is deprecated; "
> String "#offset" "#offset"
> String "#of is deprecated; " "#of is deprecated; "
> String "#new_start" "#new_start"
> String "#newsg is deprecated; " "#newsg is deprecated; "
> String "#start" "#start"
> String "#sg is deprecated; " "#sg is deprecated; "
> String "# alias_method :format, :strftime\n" "# alias_method :format,
> :strftime\n"
> String "# $Id: format.rb,v 2.14 2004-11-06 10:58:40+09 tadf Exp $\n" "#
> $Id: format.rb,v 2.14 2004-11-06 10:58:40+09 tadf Exp $\n"
> String "# format.rb: Written by Tadayoshi Funaba 1999-2004\n" "#
> format.rb: Written by Tadayoshi Funaba 1999-2004\n"
> File "#<File:0x101c41a8>" #<File:/usr/lib/ruby/1.8/date/format.rb
> (closed)>
> 17:03:55 [source]:
>
> Kind regards
>
> robert
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing a class for good from ObjectSpace Florian Weber Ruby 10 10-21-2005 06:40 PM
ObjectSpace::_id2ref and GC Ara.T.Howard Ruby 2 06-06-2005 11:43 PM
object id, objectspace, ip addresses zuzu Ruby 6 10-05-2004 04:07 PM
Ca ObjectSpace be used with SQL Server 2000? Showjumper ASP .Net 2 01-28-2004 02:26 AM
Test::Unit leaving phanthom objects in ObjectSpace? james_b Ruby 2 08-02-2003 01:08 AM



Advertisments