Comments found in ObjectSpace

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

simple answer: those are no comments

try:

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

grtz,
wannes

···

On 11/10/05, Amarison <amarison@hotmail.com> 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

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" <oeaniz@gmail.com> wrote in message
news:293701e50510110641u39865f4h@mail.gmail.com...

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

···

On 11/10/05, Amarison <amarison@hotmail.com> wrote:

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

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" <bob.news@gmx.net> wrote in message
news:3r22kqFg2irsU1@individual.net...

···

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