Hi Stefan,
schöner Demonstrations-Code!
Für jedes Zeichen wird also intern ein Objekt erstellt.

Alexander

Am 21.11.07 schrieb Stefan Tilkov <[EMAIL PROTECTED]>:
>
> Wenn ich den Code leicht modifiziere
>
> class Class
>    @@count = 0
>    alias_method :original_new, :new
>    def new(*args)
>      print "\n#{@@count}: self==#{self}\n"
>      @@count = @@count + 1
>      result = original_new(*args)
>      print "Unattended laptop error."
>      return result
>    end
> end
>
> gibt irb folgendes aus:
>
> irb(main):021:0> i = [1,2,3]
>
> 1: self==RubyToken::TkIDENTIFIER
> Unattended laptop error.
> 2: self==RubyToken::TkSPACE
> Unattended laptop error.
> 3: self==RubyToken::TkASSIGN
> Unattended laptop error.
> 4: self==RubyToken::TkSPACE
> Unattended laptop error.
> 5: self==RubyToken::TkLBRACK
> Unattended laptop error.
> 6: self==RubyToken::TkINTEGER
> Unattended laptop error.
> 7: self==RubyToken::TkCOMMA
> Unattended laptop error.
> 8: self==RubyToken::TkINTEGER
> Unattended laptop error.
> 9: self==RubyToken::TkCOMMA
> Unattended laptop error.
> 10: self==RubyToken::TkINTEGER
> Unattended laptop error.
> 11: self==RubyToken::TkRBRACK
> Unattended laptop error.
> 12: self==RubyToken::TkNL
> Unattended laptop error.=> [1, 2, 3]
>
>
> ... woran Du die Objekte erkennst, die der IRB im Hintergrund anlegt
> (bei einem direkten Aufruf sieht man, zumindest auf meinem System,
> nichts - vermutlich weil der Code im "Normalfall" eher in C als in
> Ruby geparst wird).
>
> Stefan
> --
> Stefan Tilkov, http://www.innoq.com/blog/st/
>
> On Nov 21, 2007, at 4:30 PM, Alexander Seidl wrote:
>
> > Hi,
> > In einem Buch von Bruce Tate namens "Beyond Java" habe ich ein
> > Anwendungs-Beispiel für die o.g. Methode gefunden:
> >
> >         class Class
> >           alias_method :original_new, :new
> >           def new(*args)
> >             result = original_new(*args)
> >             print "Unattended laptop error."
> >             return result
> >           end
> >         end
> >
> > gibt man diese Klasse in irb ein und erstellt ein Array mit i =
> > [1,2,3] wird, wie sollte es anders sein, "Unattended laptop error"
> > ausgegeben. Aber: 9 Mal, also:
> >
> > "Unattended laptop errorUnattended laptop errorUnattended laptop
> > errorUnattended laptop errorUnattended laptop errorUnattended laptop
> > errorUnattended laptop errorUnattended laptop errorUnattended laptop
> > error"
> >
> > Hat jemand eine Erklärung für diese Phänomen? Mir ist total
> > schleierhaft, warum es neun Ausgaben gibt. Anscheinend werden 9
> > Objekte erzeugt, obwohl ich nur ein Array erzeugt habe.
> >
> > Gruß,
> > Alexander
> > _______________________________________________
> > rubyonrails-ug mailing list
> > [email protected]
> > http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug
>
> _______________________________________________
> rubyonrails-ug mailing list
> [email protected]
> http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug
>
_______________________________________________
rubyonrails-ug mailing list
[email protected]
http://mailman.headflash.com/mailman/listinfo/rubyonrails-ug

Antwort per Email an