comments found in ObjectSpace

Discussion in 'Ruby' started by Amarison, Oct 11, 2005.

  1. Amarison

    Amarison Guest

    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
    Amarison, Oct 11, 2005
    #1
    1. Advertising

  2. Amarison

    wannes Guest

    On 11/10/05, Amarison <> 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
    wannes, Oct 11, 2005
    #2
    1. Advertising

  3. Amarison

    Barson Guest

    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" <> wrote in message
    news:...
    On 11/10/05, Amarison <> 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
    Barson, Oct 11, 2005
    #3
  4. 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
    Robert Klemme, Oct 11, 2005
    #4
  5. Amarison

    Barson Guest

    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" <> wrote in message
    news:...
    > 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
    >
    Barson, Oct 11, 2005
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Showjumper
    Replies:
    2
    Views:
    283
    Showjumper
    Jan 28, 2004
  2. james_b
    Replies:
    2
    Views:
    110
    james_b
    Aug 2, 2003
  3. zuzu
    Replies:
    6
    Views:
    150
    why the lucky stiff
    Oct 5, 2004
  4. Ara.T.Howard

    ObjectSpace::_id2ref and GC

    Ara.T.Howard, Jun 6, 2005, in forum: Ruby
    Replies:
    2
    Views:
    131
    Ara.T.Howard
    Jun 7, 2005
  5. Florian Weber
    Replies:
    10
    Views:
    293
    Paul Brannan
    Oct 21, 2005
Loading...

Share This Page