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:
------------CODE--------------
class Song def initialize(name, artist, duration) @name = name @artist = artist @duration = duration end
end
song = Song.new("Ruby Tuesday", "Rolling Stones", 360) song.inspect
------------CODE--------------
however when I use the "Run" command the output window shows up blank - no errors, just blank. adding this line to the class:
printf("foo")
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 type...
so, I'm obviously a bit of a noob - can you tell me what's going on?? is there some kind of limitation to the RubyMate bundle that doesn't allow passing of parameters into instantiated objects??
any kind of help would be great - I LOVE TM and use it for everything else I do so I'd love to use it for this too!
I should add that I'm running the latest version of OS X 10.6 and TM version 1.5.8 and that I have NOT installed Ruby via Terminal or anything else - I assumed that TM's RubyMate is a full fledged runtime environment for code testing... perhaps that I my mistake?? thanks in advance bennett
On Thu, Jun 17, 2010 at 7:49 PM, plastichairdoo plastichairdoo@gmail.com wrote:
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:
------------CODE--------------
class Song def initialize(name, artist, duration) @name = name @artist = artist @duration = duration end
end
song = Song.new("Ruby Tuesday", "Rolling Stones", 360) song.inspect
------------CODE--------------
however when I use the "Run" command the output window shows up blank - no errors, just blank. adding this line to the class:
printf("foo")
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 type...
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 (http://en.wikipedia.org/wiki/Interactive_Ruby_Shell ), 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 TextMate.
Cheers, Chris -- http://blog.rebertia.com
EXACTLY! that's it precisely, appreciate the timely response!! perhaps I missed this in the documentation somewhere? I couldn't find anything on the nuts and bolts of the RubyMate interpreter...
anyway thanks alot! bennett
On Jun 17, 2010, at 7:59 PM, Chris Rebert wrote:
On Thu, Jun 17, 2010 at 7:49 PM, plastichairdoo plastichairdoo@gmail.com wrote:
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:
------------CODE--------------
class Song def initialize(name, artist, duration) @name = name @artist = artist
<snip>
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 type...
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 (http://en.wikipedia.org/wiki/Interactive_Ruby_Shell ), 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 TextMate.
Cheers, Chris -- http://blog.rebertia.com
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate