into the console or paste it in. The new line character signals each line of code to be evaluated so this can be invoked with a key press or pasting code. The results of each line are evaluated are printed back to the console. The console maintains a context so definitions, objects, and variables continue to exist in each console session.
=> "I typed this" >> puts "I typed this" I typed this => nil Tuesday, January 8, 13 This is a typed input example. Notice that each line is evaluated after the shell reads the new line character. Also, take note how the result of each evaluation is returned to the shell. The ruby function p prints a string and returns the value of it’s input inspected. The ruby function puts prints a string and returns nothing.
=> nil Tuesday, January 8, 13 This is a pasted input example in which the input string has new lines with in it. The console prints back each line but does not evaluate the code until a valid statement has been reached.
= a+2 => 3 >> c = b+3 => 6 >> b => 3 Tuesday, January 8, 13 This example illustrates how variables are retained in the shell’s context. variables b and c and based on previous variables for example.
--- :a: 89 :zz: top => {:a=>89, :zz=>"top"} >> j = _ => {:a=>89, :zz=>"top"} Tuesday, January 8, 13 An example of irb with interactive vim. Notice editing the object opens vim on the object serialized to yaml and that it returns a new object. Also notice the underscore variable is the last returned value and I assign that value to the variable j.
edit/paste code • load/save command history • tab completion on object methods • lots of other extras ... Tuesday, January 8, 13 irbtools has many features, code and output colorization, method locator, interactive editor, and more. I think it’s best to start with your own small irbrc and modify to suit your needs. Once you have a better grasp of the potential modifications
by me at a Ember.js meetup • Nerd on a bike - http://cycling-review.com/2010/04/bike- snob/ • Nerd on a hover bike - http://iamasupernerd.com/science- nerd/real-hover-bike/ • Ork Battlewagon - http://whitescars-army.blogspot.com/ 2011/07/defeating-ork-battlewagon-list-part-1.html • Modern Jeb Clampett - http://www.cybersalt.org/funny-car- pictures/jed-clampett-2 Tuesday, January 8, 13