
ruby
Get flash to fully experience Pearltrees
Ruby Programming/Unit testing - Wikibooks, collection of open-content textbooks
Unit testing is a great way to catch errors early in the development process, if you dedicate time to writing appropriate and useful tests. As in other languages, Ruby provides a framework in its standard library for setting up, organizing, and running tests called Test::Unit. # File: simpleNumber.rb class SimpleNumber def initialize ( num ) raise unless num. is_a ? ( Numeric ) @x = num end def add ( y ) @x + y end def multiply ( y ) @x * y end endRuby Best Practices - Reading Ruby's Standard Library for Fun and Profit
Note: This post is inspired by JEG2’s excellent code reading talk at MWRC 2009, called LittleBIGRuby Go watch it if you have time, then come back and read this. You might also want to check out the Question 5 Ways interview at Pat Eyler’s “On Ruby” blog for more code reading goodness. We all need to hunt bugs and we all need to integrate our code with other systems.Ruby Readline
The GNU Readline library provides a set of functions for use by applications that allow users to edit command lines as they are typed in. (…) The Readline library includes additional functions to maintain a list of previously-entered command lines, to recall and perhaps reedit those lines, and perform csh-like history expansion on previous commands. Users that have worked with the shell are very familiar with readline. This is the library that provides ⌃A , ⌃E , ↑ , ↓ , and a number of other keyboard shortcuts that you probably expect to have when working in a shell. Ruby ships with support for working with readline (or libedit). You just need to include the Readline module: It takes just a few lines of Ruby to get the basic functionality and the core advantages that Readline provides such as keyboard shortcuts and history.Make sure to add Gemfile.lock to your repository. This will ensure that other developers on your app, as well as your deployment environment, use exactly the same third-party code as you just installed. In some cases, running executables without bundle exec may work, if the executable happens to be installed in your system and does not pull in any gems that conflict with your bundle. However, this is unreliable and is the source of considerable pain. Even if it looks like it works, it may not work in the future or on another machine.

