Sunday, March 11, 2012

In the name of Design

In the name of design, Google is killing its simple look across all its sevices that previously attracted millions of people ..

But yeah, it's just my personal opinion!


P.S, It's hard to express some stuff in 140 characters

Thursday, February 2, 2012

Rendering HTML in Rails for Dummies!

Views can be rendered in 4 simple ways from an action method.

1. Render the action's own template, named after the action's name itself. This is the default.

2. Render some other action's template from an action method, inside the same controller.

3. Render an action's template which is present in some other controller, other than the one we are calling from. 

4. Render any damn template file.


To learn more details on rendering views, see Rails guides.

Saturday, August 13, 2011

Difference between Proc and Lambda

Proc and Lambda are used to create code blocks. After creating them, we can pass them around our code, just like variables.

But there are 2 significant differences we have to keep in mind.

1. Suppose a Proc or a lambda is used to create a code block inside of a method. If the Proc/Lambda has a return statement inside of its code, in the case of Proc, the whole method is returned. But in the case of Lambda, its not. The execution continues to any further statements inside the method. Here is the code fragment that explains this difference.



2. A Proc will not check if the arguments are passed to it are of the same number as its parameters. A Lambda will throw an error if we violate the number of parmeters.




You see, Proc is very naughty :) It won't check for the number of arguments and it will return without the permission of the method in which it resides!

Saturday, June 18, 2011

RVM, RubyGems and Bundler - How gems are installed ?

Earlier when I started programming using ruby (system ruby), it was all clean. I used to install gems with sudo gem install somegem . Then came rvm and it asked me to install gems without sudo like: gem install somegem. Then came bundler, which asked me to install gems by bundle install.

Since then, I was confused about how things work using these 2 tools on top of ruby. Well, I decided to put an end to that confusion and here is how they work.

When you use



rubygems would install that gem in the place defined by $GEM_HOME environment variable. Now this is the variable that dominates where rvm puts gems in and where bundler puts gems in.

I suppose you are using rvm to manage multiple rubies. When you switch rubies using rvm, the $GEM_HOME variable changes. rvm changes it.



When we use bundler install to manage dependencies, bundler simply call gem install under hood for each of the gems defined in Gemfile. Lets see this in terminal.

First create a new rails project, it comes with a Gemfile.



Lets then create a new gemset for this project and use it



Install bundler and check $GEM_HOME location for any gems installed.



Do a bundle install in this project and check $GEM_HOME again.