view · edit · history · print

Ruby

Links:

Commands:

  • List(local)>> gem list # to install gem> yum install rubygems
  • search(remote)>> gem search -r <string>
  • install>> gem install rails
  • debug>> ruby -r debug <filename>
  • profiler>> ruby -r profile <filename>
  • Interactive>> irb
  • Information>> ri Array #case sensitive, to install ri> yum install ruby-ri
  • Documentation>> rdoc #generates doc/index.html for current dir

Samples:

Learn by example: RubyScriptingSample1.

quick references

command-line one-liners

Compilation

Can you compile Ruby? The simple answer is that you can't, at least with MRI 1.8 (the standard). This is because 1.8 works by walking the Abstract Syntax Tree. Python, Ruby 1.9, JRuby, and Rubinius use byte code, which allows compilation to an Intermediate Representation (byte code). With Rubinius, you can do something as described in this post: http://rubini.us/2011/03/17/running-ruby-with-no-ruby/ In JRuby you can use the Ahead Of Time compiler through, I believe, jrubyc. This isn't really the standard way of doing things and you're generally better off just letting your ruby implementation handle it like it wants to. Rubinius, at least, will cache byte code after the first compilation, updating it as it needs to.

Random

#!/usr/bin/ruby -w

$var = global variable
@var = instance variable
@@var = class variables

block { ... }
block do ... end


eof

admin · attr · attach · edit · history · print
Page last modified on September 12, 2015, at 05:58 AM