comments found in ObjectSpace

A

Amarison

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
 
W

wannes

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
 
B

Barson

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.


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
 
R

Robert Klemme

Barson said:
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
 
B

Barson

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 said:
Barson said:
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
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top