I have a small program designed to run on IRB. It ultimately outputs what looks like an array, although technically it is not an array. (The class inherits from the array.) The problem is when I make an instance of this class, for example. example = Awesome.new (1,2,3) and I write "puts example", the default IRB behavior is to put each element of the example on its own line.
So instead
[1,2,3]
(this is what I want) IRB issues this.
1 2 3
Is there any reasonable way to override the puts method for this special class? I tried this, but it did not work.
def puts self.to_a end
Any idea what I'm doing wrong?
Update: I tried this but did not succeed.
def to_s return self end
So, when Iโm in IRB and I just type โexampleโ, I get the behavior that I am looking for (ie [1, 2, 3]. So I decided that I could just return myself, apparently that spoiled something, what I do not understand?
source share