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 3

< Previous Page              Next Page >
Question: Can you explain the concept of inheritance in Ruby. How does it work and what are its benefits?
Answer: In Ruby Inheritance is a fundamental feature of object-oriented programming, where a class can inherit attributes and methods from another class.
The subclass (or child class) inherits all properties of the superclass (or parent class) and can also define its own unique attributes and methods. Inheritance promotes code reuse, modularity, and hierarchy in the codebase.

Question: What is the purpose of the 'include' and 'extend' keywords in Ruby and how do they differ?
Answer: Below one can find the comparison:
'include' is used to mix module methods into a class as instance methods, allowing the class to access those methods.
'extend' is used to add module methods as class methods, enabling the class itself to access those methods.

Question: Can you explain the concept of method chaining in Ruby?
Answer: The Method chaining is a technique where multiple method calls are chained together in a single line, with each method operating on the return value of the previous method.
It allows for concise and readable code by eliminating the need for intermediate variables.

Question: What is the purpose of the Enumerable module in Ruby?
Answer: The Enumerable module provides a set of methods for iterating and manipulating collections such as arrays, hashes, and ranges. It includes methods like each, map, select, reduce, etc.

Question: Can you explain the concept of a singleton class (or eigenclass) in Ruby?
Answer: A singleton class is a special class associated with a single object in Ruby. It contains methods that are specific to that object only.
Singleton classes are used to define methods for individual objects without affecting other instances of the same class.

Question: Can you explain the concept of monkey patching in Ruby and is it recommended?
Answer: In Ruby monkey patching is the practice of dynamically modifying or adding methods to existing classes or modules at runtime. While it can be a powerful tool for extending functionality, it can also lead to unexpected behavior, conflicts, and difficulties in debugging.
It's generally not recommended unless absolutely necessary and should be used with caution.

Question: How does lazy evaluation work and what are the benefits?
Answer: The 'Lazy evaluation' is a technique where the evaluation of an expression is delayed until its value is actually needed. In Ruby, lazy evaluation is commonly used with enumerators and infinite data structures.
It helps improve performance and memory efficiency by only computing values when they are required.

Question: What is the purpose and difference of the 'public', 'private', and 'protected' access modifiers in Ruby?
Answer: Below one can find the comparison:
public: Methods defined as public can be called by anyone, both from within the class and from outside.
private: Methods defined as private can only be called from within the class where they are defined, not from outside.
protected: Methods defined as protected can be called within the defining class and by instances of subclasses.


< Previous Page Next Page >