df command

The df command, which stands for “disk filesystem”, shows a summary of the available and used disk space on your Linux system. With the -h option it shows the disk space in “human readable” form, which in this case means, it gives you the units along with the numbers. For example,

df -h

will output a table with four columns. The first column contains the file system path, which can be a reference to a hard disk or another storage device, or a file system connected through the network. The second column shows the capacity of that file system. The third column shows the available space, and the last column shows the path on which that file system is mounted. The mount point is the place in the directory tree where you can find and access the that file system.

Calling multiple redirects or renders

An action may contain only a single render or a single redirect. Attempting to try to do either again will result in a DoubleRenderError:

def do_something
  redirect_to :action => "elsewhere"
  render :action => "overthere" # raises DoubleRenderError

If you need to redirect on the condition of something, then be sure to add “and return” to halt execution.

def do_something
  redirect_to(:action => "elsewhere") and return if monkeys.nil?
  render :action => "overthere" # won't be called if monkeys is nil

default arguments

When call a method with blank value in default arguments/with no argument in the position of default argument, the method uses the default value automatically….This is like “overload” in C++

What’s the idiom in Ruby when you want to have a default argument to a function, but one that is dependent on another parameter / another variable? another parameter / another variable?

def foo(a, l = a.size) end


let(:user) { mock_model(User) }

it “should mock a user” do
@user = mock_model(User)

before(:all) do
@user = mock_model(user)

before(:each) block { a=mock(User)

Mocks are implicitly verified and cleared out after(:each) so they won’t work in before(:all).

mock doesnot work in an example group (describe() block), but it works in an example (it() block).

update attribute

def name=(name)
write_attribute(:name, name.capitalize)

def name
read_attribute(:name).downcase # No test for nil?

Image what will happen if you don’t use read_attribute or write_attribute

def name
=!= booom, infinite loops, think it about why

idiomatic adj.  [idi] didaode, fuheyuyanxiguan de



add new columns in csv file

Psudo code:

FasterCSV.parse(file, parse_options) do |row|
// hanle header
if header
row.push(“new col”)
// handle the column value of the “new column”


A shortcut for appending multiple fields. Equivalent to:

args.each { |arg| faster_csv_row << arg }

This method returns the row for chaining.


# File lib/faster_csv.rb, line 253
def push(*args)
args.each { |arg| self << arg }

self # for chaining