Ruby Programming Language Notes and Reference
We have decided to use Ruby as our first language to debug threads for. So the point of this page is not so much that you are awesome at Ruby and that you can do everything in Ruby, but moreso that you can actually program non-trivial bits of code (I'm thinking threads and mutexes, specifically) to test against our debugger.
Ruby was designed by Yikihiro "Matz" Matsumoto (good luck, it's in Japanese). His philosophy is "I am trying to make Ruby natural, not simple." You can read a survey of Ruby's heavy-hitting features at the about page, but the general things are below.
- Ruby is an imperative, object-oriented language, like C++.
- Everything in Ruby is an object (and everything you can do is an object method).
- The source code for Ruby is comparatively small
- The language syntax is easy to learn
- The documentation is (presumably) mostly in Japanese.
Ruby Itself
Getting Ruby
The ruby-lang.org Downloads Page will have everything you need for any platform. Ruby is, at this point, a completely interpreted language, so there really needn't be any complex things about it. Running a script is as easy as running ruby myScript.rb.
As part of the project, you will need the Ruby source code on hand until we get some basic control over the language working. There is some decent documentation hidden in the mess. Download the source today!
Learning Ruby
The first place you should go to learn the language Ruby is the on-line ruby terminal. This remarkable little thing has some built-in commands for you, and the tutorial-like ones are especially good. The first thing you should do is type help at the prompt. Seriously, do it; it's awesome.
After that, if you're interested in doing some reading, you should read the Cartoon Foxes book. It will probably be good. It might drive you crazy. It will probably make you laugh.
References for Ruby
References for different parts of Ruby, in no particular order.
Documents the underlying C code of Ruby in the sense that everything is grouped intelligently. What's not here is any actual english that describes what is going on. Probably useful for something.
Ruby Built-In Class Reference::
Since everything in Ruby is a class, most of the language is represented by this class reference. Threads are here, and so are Integers. Pretty much any piece you get stuck on, once you have some basic concept of how to write in Ruby, is answered here.
Debugging Ruby (notes)
There is a highly relevant section in the Ruby readme for extension development. It is called "Use Ruby features from C," on line 317 of README.EXT. Once again, you can find this file by downloading the source code.
Embedded execution of Ruby in C/C++
Embedded execution means executing a program in language A using language B, programmatically.
sandbox/embedded_ruby is an open experiment where we are asserting control over arbitrary scripts in Ruby. The latest revision (r3) can only execute an entire script indivisibly. Much work is left to do.
Goals include:
- Execute simple scripts line-by-line
- Properly handle conditional jumps (if statements, loops) and unconditional jumps (function calls)
- Detect and handle context switches between multiple threads of execution.
