Category:Ruby

Essential References

 * Ruby Reference - built-in Ruby classes and modules
 * Standard Library Documentation
 * Pragmatic Programmer's Guide - (other version) - (Regular Expressions section)
 * RDOC - Ruby Documentation System

Tutorials

 * Ruby Inside:Cheat Sheets
 * Ruby Cheat Sheet
 * Why’s (Poignant) Guide to Ruby has got to be the funniest programming tutorial ever written! You must read this, even if you already know Ruby!
 * The Unofficial Ruby Usage Guide - originally a internal Google document

Extensions

 * RubyForge Software Map
 * One-click Ruby Windows Installation
 * Distributing Ruby Applications - Theory and Practice of Building, Packing and Distributing Ruby Applications (home of RubyScript2Exe)

Ruby Pages
Windows Ruby - Utility Ruby - Object-Oriented Ruby - Ruby Tricks - Ruby and Vim - Rake - Ruby on Rails - Ruby UI - Parse XML in Ruby - Ruby Web Spider

Functional Programming Example
s = lambda { |x| x.gsub!(/-/,'-=-') } t = '-' 5.times{ s.call(t) } puts t

Commands
ruby -e 'command;command'                   execute one line of Ruby code ruby program.rb                             execute Ruby program ruby -pe 'gsub(/regex/,"replacement")'      like sed ruby -pi 'gsub(/regex/,"replacement")' file like 'sed -i' (in-place) irb                                         interactive ruby shell ri -c                                       list all Ruby classes known to ri ri Dir.open                                  get documentation for Dir.open

Why Ruby?
I like ruby, because it's intuitive, concise and very object-oriented.

Just to prove my point, check out the shortest fully functional 3D vector class I have ever written in any language.

class Vector attr_reader :x, :y, :z def initialize(x, y, z) @x, @y, @z = x, y, z end def to_s ("(%+4.2f, %+4.2f, %+4.2f)" % [@x, @y, @z]).gsub(/\+/, " ") end def +(o) Vector.new(@x + o.x, @y + o.y, @z + o.z) end def -(o) Vector.new(@x - o.x, @y - o.y, @z - o.z) end def *(o) case o            # scalar multiplication when Numeric then Vector.new(@x * o, @y * o, @z * o)             # dot product when Vector then o.x * @x + o.y * @y + o.z * @z end end def ==(o) @x == o.x and @y == o.y and @z == o.z end end

It has 'get'-methods for the elements, constructor, string output, addition, subtraction, scalar multiplication, dot product, and equality...

Modules
Ruby has third-party support for unit testing, mySQL, OpenGL, among others.

Stand-alone Ruby Programs


Try RubyScript2Exe. It packs all the necessary libraries into a single executable, and it works both on Linux and Windows.

Check out this Windows executable made with RubyScript2Exe.

* NOTE: When running the program, you must end the simulation by pressing a key, and not by closing the window. There's a bug in the OpenGL for Ruby implementation, it doesn't handle closing of the window, and a 'rubyw.exe' process will keep running, eating all your processing power. Anyways, if you forget, you can always just kill rubyw with ctrl+shift+esc.