You'll Be Seeing Ruby

An Introduction to the Ruby Programming Language

Mission Data

Chuck Fouts and Darren Day

You'll Be Seeing Ruby...

What is Ruby?

I, as a language maniac and OO fan for 15 years, really really wanted a genuine object-oriented, easy-to-use scripting language.

- Matz, [ruby-talk:00382] Re: history of ruby

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/382

Very Brief Ruby Timeline

Ruby Fundamentals

The Principle of (Matz's) Least Surprise

Understand these fundamentals, and not much in Ruby will surprise you.

Try Ruby without Ruby

tryruby.hobix.com

Ruby Releases

Installing Ruby

What Do You Get?

Default Library

$ ruby -e 'puts Module.constants.join(" ")'

ARGF ARGV ArgumentError Array Bignum Binding Class Comparable Continuation Data Dir ENV EOFError Enumerable Errno Exception FALSE FalseClass File FileTest Fixnum Float FloatDomainError GC Hash IO IOError IndexError Integer Interrupt Kernel LoadError LocalJumpError Marshal MatchData MatchingData Math Method Module NIL NameError NilClass NoMemoryError NoMethodError NotImplementedError Numeric Object ObjectSpace PLATFORM Precision Proc Process RELEASE_DATE RUBY_PLATFORM RUBY_RELEASE_DATE RUBY_VERSION Range RangeError Regexp RegexpError RuntimeError STDERR STDIN STDOUT ScriptError SecurityError Signal SignalException StandardError String Struct Symbol SyntaxError SystemCallError SystemExit SystemStackError TOPLEVEL_BINDING TRUE Thread ThreadError ThreadGroup Time TrueClass TypeError UnboundMethod VERSION ZeroDivisionError

Standard Library

abbrev base64 benchmark bigdecimal cgi complex csv curses date dbm delegate digest dl drb English enumerator erb etc fcntl fileutils finalize find forwardable ftools gdbm generator getoptlong gserver iconv importenv io/wait ipaddr jcode logger mailread mathn matrix mkmf monitor mutex_m net/ftp net/http net/imap net/pop net/smtp net/telnet nkf observer open-uri open3 openssl optparse ostruct parsedate pathname ping pp prettyprint profile profiler pstore pty racc racc/parser rational rdoc readbytes readline resolv resolv-replace rexml rinda rss runit scanf sdbm set singleton soap socket stringio strscan syck sync syslog tcltklib tempfile test/unit thread thwait time timeout tk tmpdir tracer tsort un uri weakref webrick Win32API win32ole wsdl xmlrpc xsd yaml zlib

Need More Classes?

irb


irb(main):001:0> puts "Hello Ruby" Hello Ruby => nil irb(main):002:0> 3 + 5 => 8

ruby command


ruby hello.rb howdy there
ruby -e "a = 3" -e "b = 5" -e "puts a + b" 8

Anatomy of an .rb

require 'set' set = Set.new [1,2,2,3,4,5,1,2,3,5,5].each { |item| set.add item } puts set.size # what? no Hello World?

Editors and IDEs

The Pickaxe Book

  • Programming Ruby: The Pragmatic Programmer's Guide
    www.pragmaticprogrammer.com
  • Get this book before spending another dime on Ruby
  • The Pickaxe Book because of the cover 2 editions running
  • First edition available for free online, second edition worth the scratch
  • Thanks Dave Thomas, Andy Hunt, and Chad Fowler!

ri Command


$ ri Object $ ri select $ ri Object#to_s $ ri IO::open $ ri Hash.length

Documentation Online

On to the Language