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 1

Next Page >
Question: What is Ruby and what are its key features?
Answer: The Ruby is a dynamic, object-oriented programming language known for its simplicity and productivity.
Its key features include dynamic typing, automatic memory management, and a strong focus on developer happiness and productivity.

Question: Can you explain the difference between puts, print, and p in Ruby?
Answer: Below one can find the difference:
• puts: Outputs the result with a newline at the end.
• print: Outputs the result without a newline.
• p: Outputs the result as it is, including quotes and escape characters, and returns the value.

Question: What are symbols in Ruby and how are they different from strings?
Answer: in Ruby, Symbols are lightweight identifiers represented by a colon followed by a name, like :symbol_name. They are immutable and unique throughout the program, making them efficient for things like hash keys.
Strings, on the other hand, are mutable and can be modified.

Question: Can you explain the concept of blocks in Ruby?
Answer: The Blocks are chunks of code enclosed within '{}' or 'do...end'. They can be passed to methods as arguments and are often used for iteration and callback functionality.
Blocks can take parameters and are executed in the context of the method they're passed to.

Question: What is a module in Ruby and how is it different from a class?
Answer: A module in Ruby is a collection of methods and constants. Unlike classes, modules can't be instantiated and don't have instances. They serve as containers for methods that can be mixed into classes using include keyword.
Modules promote code reusability and provide a namespace.

Question: Can you explain the concept of mixins in Ruby?
Answer: In Ruby Mixins are a way to simulate multiple inheritance. They allow classes to inherit behavior from multiple modules by using the include keyword.
This enables code reuse and promotes modular design without the complexities of traditional multiple inheritance.

Question: What is the difference between attr_accessor, attr_reader, and attr_write?
Answer: Here is the difference;
attr_accessor: Automatically defines both getter and setter methods for a class attribute. • attr_reader: Automatically defines a getter method for a class attribute. • attr_writer: Automatically defines a setter method for a class attribute.

Question: Can you explain the concept of duck typing in Ruby?
Answer: In Ruby duck typing is a concept where the suitability of an object for a particular purpose is determined by whether it responds to method calls rather than the object's class or inheritance hierarchy.
If an object responds to the required methods, it can be used for that purpose regardless of its actual type.


Next Page >