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!
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.