Skip to content

Instantly share code, notes, and snippets.

@erithmetic
Created September 24, 2010 02:00
Show Gist options
  • Save erithmetic/594744 to your computer and use it in GitHub Desktop.
Save erithmetic/594744 to your computer and use it in GitHub Desktop.

Ruby Intro

Ruby is a program

It takes ruby code as input and runs it. => Interpreted => No compiling(*)

Other programs

  • irb

Standard library

  • Ruby comes with an amazing amount of tools out of the box Net::HTTP Net::SMTP/IMAP/POP3 Matrix CSV DRb DateTime FileUtils Logger SOAP (yes, SOAP!) Zlib

See also: http://www.ruby-doc.org/core/ and http://www.ruby-doc.org/stdlib/

All kinds of rubies

  • MRI (1.8.6, 1.8.7, 1.9.1, 1.9.2)
    • 1.8.7: Safest verison - best compatibility
    • 1.9.x: Bleeding edge - faster, will be required by Rails 3.1
  • Ruby Enterprise Edition
    • Memory optimized MRI 1.8.7
  • JRuby
  • Rubinius
  • IronRuby
  • Maglev

Basic add-ons

Rubygems

  • Similar to a package manager in Linux or CPAN in Perl or Python eggs
  • gem executable
  • Find gems
    • gem list rspec
  • Install gems
    • gem install rails
    • sudo vs sudon't
  • Build gems
  • Release gems to rubygems.org

Rake

  • A Ruby gem for running quick scripts
  • rake : Ruby :: make : C

Example: # Rakefile

task :test do
  # run testing code
end

task :release do
  `gem push mygem.gemspec`
end

rake test
#=> All tests pass!

Testing

  • Testing is highly valued among the Ruby community - many are passionate about quality software and switched to Ruby because the language reflects their values of pragmatism and beauty. Testing is a practice of pragmatism and helps us write beautiful code.
  • More test suites than you can shake a stick at
    • RSpec, Cucumber, Test::Unit, Shoulda, Bacon, Coulda, Steak, Riot
  • Tests are typically executed by running rake test

Gems for common tasks

| Date/Time parsing | chronic | | Gem building | jeweler | | Geocoding | geokit | | PDF Generation | prawn | | Workflow engine | ruote | | HTML/XML Parsing | nokogiri | | Web scraping | mechanize |

See also: http://ruby-toolbox.com/

Gem bundler

A tool for "locking" a specific set of gems that a ruby program can use. Tries to prevent "DLL Hell." Rails is now intimately involved.

  • Gemfile
  • bundle update

Ruby and the web

  • Rails, duh!
  • Rails is a collection of gems and a script for generating rails apps
  • Sinatra
  • For simple web apps
  • R.I.P. Merb
  • Camping
  • Nitro

Rack

Rack is the bedrock on which most Ruby web frameworks rest. It is a simple library that handles the job of accepting an HTTP request, parsing out parameters and server environment variables, and outputting the response. Go here if you want performance. It's the closest you can get to the web server itself.

Ruby and the database

  • ActiveRecord - America's favorite "ORM"
  • Datamapper
  • Sequel

Relational database support

  • sqlite
  • mysql
  • postgres
  • MS SQL (DBI)

"NoSQL" support

  • MongoDB
  • CouchDB
  • Redis
  • Etc, etc, etc.

Ruby web deployment

Can't just copy a folder to your web server. Most servers need to be told where your web app is and which domain it should serve. Passenger for Apache is the quickest and easiest option for servers you manage. Heroku is the best for getting started quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment