On Friday 17 July 2009, Venkat A. wrote:
|> executed until an instance is created and the method is
|> Add the following to your third example after the class
|> definition block for Something:
|> Gary W.
|Thanks for replying Gary and stefano
First of all, I apologize for not having read your message carefully: I
completely missed the fact that the print_something method was inside a
At any rate, most of what I said in my answer is still correct. In the
you posted, you didn’t call the Something#print_something but only
|This I assume is thrown because the interpreter cannot find the file. I
|ran the irb command from inside the folder containing this file. Doesn’t
|irb see the file?
You need to require the file for irb to see it. Try issuing the
By the way, in the code you posted there’s no mention of something
Test. This means that the code you’re running is different from what you
showed us. In this situation, is difficult to for us to help you.
either show us the complete code or run (and report problems with) the
|Addressing what steffano said, Well I have called the print_something
|method from inside the class’s constructor. Should I not assume that
|when the file is run the class’s constructor will be called and hence
|the method will be called.
No, you didn’t (at least in the code you posted). As I said above, you
defined the method but never actually called it. To do so in a class
constructor, you should have defined an instance method called
put a call to print_something there:
The initialize method is automatically called when you do Something.new
in turn, it would call print_something. But you didnt’t define an
method and didn’t call Something.new.