From: Stefano Crocco Date: 2013-02-18T06:34:00+09:00 Subject: Re: What is Ruby's default constructor? On Monday 18 February 2013 Love U Ruby wrote > Stefano Crocco wrote in post #1097453: > > There was nothing "wrong" in your code before the 'begin'. > > > > What happened is that you redefined Object.new not to return a new > > object, but > > to return whatever > > > > p 'hi' > > > > returned (that is, the string 'hi'). This obviously messes up > > everything: IRB > > tried to create an instance of a certain class (let's call it X) by > > using > > X.new, which is the same as Object.new. However, this didn't return an > > instance of X, but a string. Then IRB tried to call the #set_backtrace > > method > > on the returned object (which should have been an instance of X but was > > instead a string). Since a string doesn't have a set_backtrace method, > > you get > > the error. > > As per your above explanation it seems and definitely an allocation to > the memory has been made and only the reference has been lost. From my > piece code - can it be possible to print also that memory address like > "object_id" like the `p "hi" ` ? > > Thanks. > > -- > Posted via http://www.ruby-forum.com/. Note that you rewrote Object.new to only print a message: it doesn't event allocate memory. If you want to see that, you need to something like: def Object.new res = super p res.object_id res end Stefano