Posted in Information Technology

Ruby

Overview

A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. Ruby is well known for developing a cli tools. Many software package managements are leveraging on ruby

Ruby

  • ruby is the Ruby Interpreter
  • ruby hello.rb runs the Ruby source file hello.rb
  • Options
    • -w – warnings
    • -v – version or verbose
    • --help
    • -c – check syntax

irb

  • Interactive Ruby Browser
  • aka “the ruby console”
  • interprets Ruby one line at a time
    • REPL: Read Eval Print Loop

uncluttering irb’s cluttered prompt

irb --simple-prompt

or

alias irb="irb --simple-prompt"

or

echo "IRB.conf[:PROMPT_MODE] = :SIMPLE" >> ~/.irbrc

ri and rdoc

  • if you’re running rvm, do this right now:
    rvm docs generate
    
  • rdoc generates and displays documentation

web docs

cheat

  • a text-only command-line wiki
  • gem install cheat for command-line tool or see http://cheat.errtheblog.com
    $ cheat agile
    Agile Manifesto_____________
     - Individuals and interactions over processes and tools 
     - Working software over comprehensive documentation  
     - Customer collaboration over contract negotiation 
     - Responding to change over following a plan 
    While there is value in the items on the right, we value the items on the left
    more.
    

rake

  • one Rakefile contains many “tasks” which can be run a la rake test
  • rake looks up the directory tree for a Rakefile
  • rake --tasks shows all defined tasks in the current Rakefile
    • also rake -T

gem

  • aka RubyGems
  • gem = Ruby package = library or program or plugin
  • gem install foo – downloads and installs the “foo” gem from rubygems.org
  • gemrvm and bundler live in uneasy harmony

gem plugins

  • installed as gems, but extend the gem command
  • for example, open_gem which opens the source code for a gem in your editor
    gem install open_gem
    gem open rake
    

bundler

  • manages lots of different sets of gems and versions thereof
  • bundler is a gem itself
    • gem install bundler loads it into the current gemset
  • bundle install
  • bundle update
  • Gemfile lists all the gems for the current project (directory)
    • similar to Rakefile in scope

rvm

  • Ruby Version Manager
  • manages lots of different versions and distros of Ruby on a single computer
    • rvm list
    • rvm install 1.9.2
    • rvm use 1.9.2
  • also manages gemsets
    • rvm gemset create teaching
    • rvm use 1.9.2@teaching
  • overlaps with gem and Bundler
    • in sometimes odd ways

Bundler vs. RVM

  • RVM manages multiple gemsets on a single machine
  • Bundler manages the same gemset on multiple machines

RSpec

  • testing framework
  • describe, it, before, after, should

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s