Here are some often used Tips and tricks with Git
Part 6: Ruby Through Rails — Bundler Dsl
What happens when you write ‘gemspec’ in your Gemfile? Learn some Ruby by understanding the Bundler DSL in this series of posts.
Earlier we seen detailed working of ‘gem'(present in Gemfile) command. For now, we are now going to introspect the working of ‘gemspec’ which we mostly used during building our rubygems. As i have mentioned in earlier serials that all command, which we used in Gemfile, found in the bundler file(lib/bundler/dsl.rb)
Let see how ‘gemsepec’ is used in gemfile.
Normally, when we write our rubygem, our directory name is the name of gem and gemspec found in same directory as “name_of_gem.gemspec”.
Let see the code of ‘gemspec’ defined in bundler(lib/bundler/dsl.rb).
Let understand above implementation with code example. Consider we have ‘dummy’ as rubygem.
Content of Gemfile of ‘dummy’ gem are:
As we do ‘bundle install’, then gemspec call without any options. Since we did not pass any options, default name, path, development_group get set as ‘.(current_directory)’, ‘{,*}’ and
‘development’ respectively. Line no 6 get ‘#{name}.gemspec’ file if name provided as nation…
View original post 159 more words
The Definition Of Nested Module
Nested modules are not what they seem. In this post, Rishi talks about the scope among nested variables. Here’s an Ah-ha! moment for you!
Learning shall never stop..!!!
When we define nested modules like this:
and when we do like this:
Even though both method calls to print_const looks same, and should return same result. But it returns different values of the constant.
Reason:
When you do this in first case:
and this gives:
So ruby looks for the constant X in the order as A::B::C, A::B, A. and it loads wherever it finds first, and as in our scenario, under module B.
And in second scenario:
and this gives:
Here since the nesting of the module is different, it only search in A::B::C and A, skipping A::B. So it finds constant X under module A.
