Reference Page: PHP|Python|Perl|Ruby|MatLab

Ruby Links : Learn     Interview Questions     Software IDE Ruby Jobs : Indeed.com     ZipRecruiter.com     Monster.com

Ruby Interview Questions - Page 2

< Previous Page              Next Page >
Question: Can you explain the concept of metaprogramming in Ruby?
Answer: The Metaprogramming is the technique of writing code that writes or manipulates code during runtime. In Ruby, this is made possible by features like eval, define_method, and the ability to open classes and modules at runtime.
Metaprogramming can be powerful but should be used judiciously due to its potential for complexity and obscurity.

Question: What is the purpose of the 'require' and 'load' methods in Ruby? How do they differ?
Answer: Both require and load are used to load external Ruby files into the current program.
require is used to load a file once and will not load the same file again if it has already been loaded. • load is used to load a file every time it's called, regardless of whether it has been loaded before.

Question: Can you explain the concept of closures in Ruby?
Answer: A closure is a function that captures the surrounding state (variables, bindings) within its scope. In Ruby, closures are created with blocks, lambdas, and procs.
They allow for the encapsulation of behavior and data, enabling functionalities like higher-order functions and callbacks.

Question: What is a Ruby gem? How do you install and use gems in your project?
Answer: A Ruby gem is a packaged Ruby application or library. You can install gems using the 'gem install' command followed by the gem name.
To use a gem in your project, you include it in your Ruby code using require or by adding it to your Gemfile if you're using Bundler, then running bundle install.

Question: Can you explain the difference between nil, false, and undefined in Ruby?
Answer: Below please find the difference:
'nil' represents the absence of a value. It's an object of the NilClass and is often used to signify "nothing"
'false' is a boolean value representing "false"
'undefined' is not a keyword in Ruby. If something is "undefined" - it typically means it hasn't been assigned a value or is out of scope.

Question: What is the purpose of the 'super' keyword in Ruby and how does it work?
Answer: The 'super' keyword is used to call the same method in the superclass from within a subclass. It allows the subclass to extend or override the behavior of the superclass while still executing the superclass's implementation of the method.

Question: Can you explain the concept of self in Ruby?
Answer: The self refers to the current object or the current instance of a class. It's used to access the current object's properties and methods within its scope.
In Ruby, self can change depending on the context in which it's used.

Question: What is the purpose of the '__FILE__' and '__LINE__' constants in Ruby?
Answer: The '__FILE__' returns the name of the current source file.
And the '__LINE__' returns the current line number in the source file.
These constants are often used for debugging and logging purposes.


< Previous Page Next Page >