Skip to main content

53 Best Ruby Interview Questions and Answers

What Is Ruby?
Ruby is an Open-Source, Pure Object Oriented Programming (OOPs) and Inspired by Perl and Python programming.
Ruby has mixed features of Perl, Smalltalk, Eiffel, Ada, Python and Lisp.
Ruby is designed and developed by Yukihiro “martz” Matsumoto in 1990 in Japan.

What Are the Key Features of Ruby?
ü  Object oriented Programming
ü  Flexible
ü  Free format
ü  Case sensitive
ü  Dynamic typing and Duck typing
ü  Garbage collector

What Is Ruby Class?
The class is an instance of Ruby class and it’s always starts with a keyword class followed by the class name.

What Is Ruby Object?
The Object is the default root of all Ruby objects that inherit from Basic Object. It is created by calling new method of the class.

What Is Ruby Methods?
Ruby methods are used to create the common methods which prevents to writing the code gain and again in the applications. It is very similar to other programming languages.

The Ruby method is defined with the def keyword and end with end keyword.
def yourMethodName 
    //TODO: your logic

What Are the different uses of Ruby modules?
ü  Namespace
ü  Traits/Mixin
ü  Singleton class alternative
ü  Bag of stateless helper methods

What Are the Ruby variables?
A Ruby variable contains the data that can be used in a program.
The types of Ruby variables -
ü  Local variable
ü  Global variable
ü  Class variable
ü  Instance variable

What Are the data Types in Ruby?
There are different Ruby data types and its looks like -
ü  Numbers
ü  Strings
ü  Symbols
ü  Hashes
ü  Arrays
ü  Booleans

What Are differences between Ruby and Python?
Ruby is pure object oriented Programming while Python is not.
Ruby supports blocks, lambdas and procs while Python is not.
Ruby supports EclipseIDE while Python supports multiple IDE.

What Are Advantages of using Ruby?
ü  Pure Object-Oriented Language
ü  Open-Source
ü  Metaprogramming
ü  Clean and Simple
What Are Class Libraries in Ruby?
Ruby contains the variety of domain as like thread programming, data types and various domains. The class library looks like -
ü  Text processing
ü  XML programming
ü  GUI programming
ü  CGI Programming
ü  Network programming

What Is the difference between nil and false in Ruby?
The “nil” can't be a value while false can be a value.
The “nil” is not a Boolean data type while false is a Boolean data type.
The “nil” is an object of “nilclass” while false is an object of “falseclass”.

What Are the Case Statement in Ruby?
Ruby case statement matches one statement with multiple conditions and also you can use “case” instead of “switch” and “when” instead of “case”.

What is Yield in Ruby?
Ruby method that receives a code block invokes it by calling it with the Yield.

How can you declare a block in Ruby?
The block is always enclosed within braces ({}) which invoke a block by using “yield statement”.
What Is the difference in scope for these two variables @@name and @name?
ü  @@name variable is a class variable
ü  @name variable  is an instance variable

What Is the difference between Procs and Blocks?
The Procs are object while blocks are not and one block can appear in an argument list.

What Is the difference between a gem and a plugin in Ruby?
The Plugin is ruby code which installed in the application folder.
The Gem is also ruby code which installed on a machine

What Are the loops in Ruby?
ü  for  loop
ü  while loop
ü  do while loop

What Is retry statement in Ruby?
The retry statement is used to repeat the whole loop iterations from the start.

How can you removed from Array in Ruby?
The array elements can be removed using -
ü  pop
ü  shift
ü  delete
ü  uniq

What Are the only two values that are falsy?
ü  false
ü  nil

Is Ruby whitespace-dependent?
Sometimes it’s dependent on whitespace.

Is Ruby a statically typed or a dynamically typed language?
Dynamically typed since type checking is done at runtime

Is Ruby a strongly typed or a weakly typed language?
Strongly typed since an object's type is checked before an operation is performed on it

What Is the difference between a statement and an expression in Ruby?
Every statement is an expression that statements return a value and a statement is simply a way to refer to a certain type of syntax.

Where does a scope change in a Ruby program?
ü  module
ü  class
ü  def

Are Ruby strings are mutable?
Yes! It is mutable.

What Is a symbol in Ruby?
Symbol is a scalar value objects and it is used as identifiers, mapping immutable strings to fixed internal values.

Are Numeric objects mutable in Ruby?
No! It is not mutable.

What happens when a value is too big for Fixnum?
It is automatically converted to a Bignum.

What method might you use to remove duplicate values from an array?
The “#uniq” method is used to remove the duplicate values from an array.

Does Hash use “ #==” or “#eql?” to compare hash keys?

What Is the pattern matching operator in Ruby?

What Is the difference between “#==” and “#equal?”
The “#==” performs the generic comparison and is used to implements different classes.
The “#equal?” is defined on BasicObject and compares object identity.
Also “#equal?” should not be overridden in sub-classes.

What Is the difference between “#==” and “#===”?
The “#==” performs the generic comparison but “#===” performs case equality comparison.

What Is the difference between #== and #eql??
The “#==” performs the generic comparison.
The “#eql?” is once in a while an alternate equality and also uses to test for hash key equality.

What Is the difference between throw/catch and raise/rescue?
The “Throw/catch” should be considered a control-flow structure while “raise/rescue” is used to raise and handle exceptions.

Can method names be capitalized?
Yes! But the convention is that they are not.

What must you do first before you can invoke an UnboundMethod object?
Bind it to a receiver object using the “#bind”.

What Is a Struct in Ruby?
A core Ruby class that generates other classes containing access or methods for the specified fields

Which Ruby interpreter option enables debugging?
-d or --debug

What does MRI most commonly stand for?
Matz's Ruby Interpreter

What does IRB stand for?
Interactive Ruby

How do you handle exceptions in Ruby code?
Using begin and rescue
By Anil Singh | Rating of this article (*****)

Popular posts from this blog

List of Countries, Nationalities and their Code In Excel File

Download JSON file for this List - Click on JSON file    Countries List, Nationalities and Code Excel ID Country Country Code Nationality Person 1 UNITED KINGDOM GB British a Briton 2 ARGENTINA AR Argentinian an Argentinian 3 AUSTRALIA AU Australian an Australian 4 BAHAMAS BS Bahamian a Bahamian 5 BELGIUM BE Belgian a Belgian 6 BRAZIL BR Brazilian a Brazilian 7 CANADA CA Canadian a Canadian 8 CHINA CN Chinese a Chinese 9 COLOMBIA CO Colombian a Colombian 10 CUBA CU Cuban a Cuban 11 DOMINICAN REPUBLIC DO Dominican a Dominican 12 ECUADOR EC Ecuadorean an Ecuadorean 13 EL SALVADOR

39 Best Object Oriented JavaScript Interview Questions and Answers

Most Popular 37 Key Questions for JavaScript Interviews. What is Object in JavaScript? What is the Prototype object in JavaScript and how it is used? What is "this"? What is its value? Explain why "self" is needed instead of "this". What is a Closure and why are they so useful to us? Explain how to write class methods vs. instance methods. Can you explain the difference between == and ===? Can you explain the difference between call and apply? Explain why Asynchronous code is important in JavaScript? Can you please tell me a story about JavaScript performance problems? Tell me your JavaScript Naming Convention? How do you define a class and its constructor? What is Hoisted in JavaScript? What is function overloadin

React | Encryption and Decryption Data/Text using CryptoJs

To encrypt and decrypt data, simply use encrypt () and decrypt () function from an instance of crypto-js. Node.js (Install) Requirements: 1.       Node.js 2.       npm (Node.js package manager) 3.       npm install crypto-js npm   install   crypto - js Usage - Step 1 - Import var   CryptoJS  =  require ( "crypto-js" ); Step 2 - Encrypt    // Encrypt    var   ciphertext  =  CryptoJS . AES . encrypt ( JSON . stringify ( data ),  'my-secret-key@123' ). toString (); Step 3 -Decrypt    // Decrypt    var   bytes  =  CryptoJS . AES . decrypt ( ciphertext ,  'my-secret-key@123' );    var   decryptedData  =  JSON . parse ( bytes . toString ( CryptoJS . enc . Utf8 )); As an Example,   import   React   from   'react' ; import   './App.css' ; //Including all libraries, for access to extra methods. var   CryptoJS  =  require ( "crypto-js" ); function   App () {    var   data

25 Best Vue.js 2 Interview Questions and Answers

What Is Vue.js? The Vue.js is a progressive JavaScript framework and used to building the interactive user interfaces and also it’s focused on the view layer only (front end). The Vue.js is easy to integrate with other libraries and others existing projects. Vue.js is very popular for Single Page Applications developments. The Vue.js is lighter, smaller in size and so faster. It also supports the MVVM ( Model-View-ViewModel ) pattern. The Vue.js is supporting to multiple Components and libraries like - ü   Tables and data grids ü   Notifications ü   Loader ü   Calendar ü   Display time, date and age ü   Progress Bar ü   Tooltip ü   Overlay ü   Icons ü   Menu ü   Charts ü   Map ü   Pdf viewer ü   And so on The Vue.js was developed by “ Evan You ”, an Ex Google software engineer. The latest version is Vue.js 2. The Vue.js 2 is very similar to Angular because Evan You was inspired by Angular and the Vue.js 2 components looks like -

Encryption and Decryption Data/Password in Angular

You can use crypto.js to encrypt data. We have used 'crypto-js'.   Follow the below steps, Steps 1 –  Install CryptoJS using below NPM commands in your project directory npm install crypto-js --save npm install @types/crypto-js –save After installing both above commands it looks like  – NPM Command  1 ->   npm install crypto-js --save NPM Command  2 ->   npm install @types/crypto-js --save Steps 2  - Add the script path in “ angular.json ” file. "scripts" : [                "../node_modules/crypto-js/crypto-js.js"               ] Steps 3 –  Create a service class “ EncrDecrService ” for  encrypts and decrypts get/set methods . Import “ CryptoJS ” in the service for using  encrypt and decrypt get/set methods . import  {  Injectable  }  from   '@angular/core' ; import   *   as   CryptoJS   from   'crypto-js' ; @ Injectable ({    providedIn:   'root' }) export   class   EncrDecrS