Subscribe Favorite

Ruby Quick Reference

Written on March 22, 2008 by ceefour

While using Ruby for your projects, you may need some references.

These are some references that might help you in using Ruby:

  • Language

General Syntax Rules

  • Comments start with a pound/sharp (#) character and go to EOL.
  • Ruby programs are sequence of expressions.
  • Each expression is delimited by semicolons(;) or newlines unless obviously incomplete (e.g. trailing ‘+’).
  • Backslashes at the end of line does not terminate expression.

Reserved words

alias   and     BEGIN   begin   break   case    class   def     defined
do      else    elsif   END     end     ensure  false   for     if
in      module  next    nil     not     or      redo    rescue  retry
return  self    super   then    true    undef   unless  until   when
while   yield

Type

Basic types are numbers, strings, ranges, regexen, symbols, arrays, and hashes. Also included are files because they are used so often.

Variables

$global_variable
@@class_variable
@instance_variable
[OtherClass::]CONSTANT
local_variable
  • Standard Library

Ruby comes with an extensive library of classes and modules. Some are built-in, and some are part of the standard library. You can distinguish the two by the fact that the built-in classes are in fact, built-in. There are no dot-rb files for them.

Built-in Library

Class Hierarchy:

Object

  • Hash
  • Symbol
  • IO
    • File
  • Continuation
  • File::Stat
  • Data
  • NilClass
  • Exception (see tree above)
  • Array
  • Proc
  • String

Standard Library

The essentials:

    • benchmark.rb a simple benchmarking utility
    • cgi-lib.rb decode CGI data - simpler than cgi.rb
    • cgi.rb CGI interaction
    • date.rb date object (compatible)
    • debug.rb ruby debugger
    • delegate.rb delegate messages to other object
    • English.rb access global variables by english names
    • fileutils.rb file utility methods for copying, moving, removing, etc.

For further details visit Ruby Quick Reference page at ZenSpider.

If you enjoyed this post Subscribe to our feed

 

Trackbacks

(Trackback URL)

close Reblog this comment
blog comments powered by Disqus