Computer Science Canada Some Ruby Help |
Author: | JHanson90 [ Fri Aug 27, 2004 11:37 pm ] | ||||||
Post subject: | Some Ruby Help | ||||||
I know at least one of you knows Ruby, or some of it anyway. I just started learning it from "Programming Ruby, The Pragmatic Programmer's Guide." Right now it's teaching me about classes, specifically Inheritance. Here's an excerpt of what the example was in the guide:
and here is an excerpt of test1.rb; my version of it to test out the example given in the guide:
As far as I know the '+' is just the thing you use to concatenate (or whatever that word is that means to put two things together). So why would it return that error? |
Author: | wtd [ Sat Aug 28, 2004 12:10 am ] | ||||||
Post subject: | |||||||
Piece#to_s (which is how I represent the to_s method of class Piece) is actually calling print. The problem with this is that print returns nil. "to_s" methods should always return a string. As long as a class has a to_s method, you can call that method and print it as easily as:
Which is equivalent to:
So your code cleaned up looks like:
Note also that when you reopen an existing class to extend it, you don't need to show what it's inheriting from, as demonstrated where I've cleaned up your extension of the MusicMinusOne class. You've got a good start, though. Keep going! |
Author: | JHanson90 [ Sat Aug 28, 2004 12:41 am ] |
Post subject: | |
Thanks for the help; it worked! |
Author: | wtd [ Sat Aug 28, 2004 3:49 am ] |
Post subject: | |
You're quite welcome. It odd, but very very nice to see Ruby code posted here that wasn't written by me. |
Author: | JHanson90 [ Mon Aug 30, 2004 3:03 pm ] |
Post subject: | |
Any Ruby IDE recommendations? Right now I'm using FreeRIDE [Free Ruby IDE], but wondering if there's anything better that you recommend. FreeRIDE was the default program that I got with Ruby, but it doesn't have as much syntax highlighting support as I would like. Auto-indenting is nice too, but I don't necessarily need that. |
Author: | wtd [ Mon Aug 30, 2004 9:23 pm ] |
Post subject: | |
I'm pretty happy just using Textpad (on Windows) and just having a cmd.exe window open. On *nix systems I usually use either vim or a graphical text editor and have a terminal window open. You might also try ArachnoRuby. I know the guy who created it. He's a brillant Ruby and Eiffel coder. |
Author: | JHanson90 [ Mon Aug 30, 2004 9:38 pm ] |
Post subject: | |
Cool, thanks again. |
Author: | JHanson90 [ Tue Sep 14, 2004 7:23 pm ] |
Post subject: | |
I want to test out the idea of using Ruby for the Web. I noticed that Ruby's website, http://www.ruby-lang.org/, has a Ruby program as it's index.*. http://www.ruby-lang.org/en/index.rb So I found out about eRuby and mod_ruby. Is eRuby any good? I'm some issues trying to install it; should I just ditch the idea? eRuby claims to be just like JSP, ASP, or PHP, but with the power of Ruby, so that sorta made me wonder if this was a good idea... |
Author: | wtd [ Mon Sep 20, 2004 11:09 am ] |
Post subject: | |
eRuby is incredibly cool, and you can use it as a program even without dealing with it via a web server. It allows you to put Ruby code into a text file. There's also an implementation of eRuby written in Ruby. Try running the "erb" command. |