The two important command-line tools are going to be "irb" and "ruby". For development, you will be able to use tools like emacs, vim, Jetbrains Rubymine, or Eclipse. Ruby support is quite widespread.
Create a temporary directory and get cozy inside.
Right off the bat, how would you write a test? You would create a file called "my_test.rb" (It is a good naming convention, 'something_test.rb').
A couple of things of note:
requireis how you load external libraries.
- The test class name (
SomethingTest) is a convention. Follow it and avoid pain.
- The test method name also follows a convention :
test_*. Again, follow it and avoid pain.
- Indentation is two spaces by convention. Follow, Avoid.
- Parentheses for method calls are optional, but it's good form to put parentheses if there are two or more arguments to a method. Also, parentheses will save you if the parser has issues parsing. Remember that.
ruby my_test.rband see one test succeed and one test fail.
How would you write a simple program?
Create a file called
myprog.rb and put the following inside:
This would be run, like the test, with ~ruby myprog.rb~ Some things to note:
gets.chomp-- Ruby, by default, captures the return key being pressed. Chomp is necessary to remove that special character.
- Did you notice how I put parentheses around
palindromize(input)? It's so that both the Ruby parser and human readers stay sane when reading the code.
Things of note:
Wanna talk to people? You can go to http://www.ruby-forum.com/ (Ruby big names, such as David Black, JEG2 and even Matz, the creator of the language) are active there, and everyone is nice. You can also go to the Freenode server on IRC, channel #ruby.
Let me know if you think I could add things to this tutorial or if you have questions!
Author Aldric Giacomoni