Friday, February 25, 2011

Ruby : Methods, Procs and Lambdas

Started reading understanding Ruby blocks, Procs and Lambdas from a link in a rails post. Very very interesting.

I learnt what blocks are, Proc object is, and the subtle difference between the Proc and Lambdas. The differences aren't many and visible, but they are interesting.

1. Proc doesn't check number of arguments while Lambdas do
2. Use lambdas to pass the 'return' keyword as a part of an argument - Ruby doesn't allow you to do that in Proc

The 2nd point is because Procs are 'drop in code snippets and not methods', but lambdas act like methods.
Lambdas are anonymous way to write methods.
To use a named lambda use the Method object and assign the code to it.

eg      puts method(:square).class

Tuesday, February 22, 2011

Rails naming-1-Migrations

Migration naming convention - _to_<table_name>

add_password_to_user - constructs a migration to the user table.

REST

This is the link to the original dissertation by Computer scientist Roy Fielding at the University of California, Irvine, 2000.


REST ignores the details of component implementation and protocol syntax in order to focus on the roles of components, the constraints upon their interaction with other components, and their interpretation of significant data elements.

How to find the rails environment

ruby-1.9.2-p0 :001 > Rails.env
=> "development"
ruby-1.9.2-p0 :002 > Rails.env.development?
=> true


Rails provides a Rails object with an env attribute and associated environment bollean methods.