Where is ‘new’ defined in Ruby? What does instance_eval do? How is a Gemfile parsed? Did you know that “gem”, “source” and “ruby” are method defined in the Bundler gem? Read and learn about more constructs and the Bundler DSL for parsing the Gemfile.
Bundler::Dsl class is defined inside the lib/bundler/dsl.rb. Earlier we have learned how various settings get set like the bundle path and gem path. Now we are going to learn how the Gemfile is parsed and evaluated. Bundler::Dsl.evaluate gets called from Bundler::Definition#build function.
‘evaluate’ method is singleton method on class Dsl and the parameters passed to it are Gemfile path, Gemfile.lock path and a boolean field from Bundler::Definition#build function. In above function, it calls the ‘new’ function. There is nothing new about the ‘new’ function. It basically creates the object for a class. Howevr, have you ever given thought where ‘new’ function defined?
What is the ‘new’ function in Ruby?
‘new’ is instance method of class Class. Classes in Ruby are first-class objects—each is an instance of class Class.When a new class is defined (typically using class SomeName … end), an object of type Class is created and assigned to a constant (SomeName, in this case)…
View original post 460 more words