On Thu, Jun 17, 2010 at 7:49 PM, plastichairdoo
hi there - I've been trying my hand at learning
Ruby and have been running some small scripts within TM but now I've run into a
problem... here's the code I'm trying to run:
def initialize(name, artist, duration)
@name = name
@artist = artist
@duration = duration
song = Song.new("Ruby Tuesday", "Rolling Stones", 360)
however when I use the "Run" command the output window shows up blank - no
errors, just blank.
adding this line to the class:
results in "foo" in the output window but nothing else.
this code is taken directly from the "Programming Ruby" book published by The
Pragmatic Programmers and should output some stuff that would take me far too long to
so, I'm obviously a bit of a noob - can you tell me what's going on??
.inspect just returns a String representing an object in a format
useful for debugging. To actually *output* the returned string, you
must pass it to puts(), printf(), or similar.
The example in the book is probably being input & run into IRB
), which by
default automatically outputs the result of each expression evaluated
at the top-level; in this case, it automatically outputs the String
returned by the expression "song.inspect".
Long story short: The interactive shell works differently than the
vanilla ruby interpreter. Either add an explicit call to puts/printf,
or input & run the code in irb from the Terminal instead of using