Saturday 9 June 2018

Ruby Interview Questions

1) What is Ruby programming language?
Ruby is a dynamic, reflective, general purpose, open source programming language that focuses on simplicity and productivity. Ruby has a mixed features of Perl, small talk, Eiffel, Ada and Lisp. Ruby was designed to create a new language which makes a balance with the functionality of Imperative languages.

2) Who is the developer of Ruby?
Ruby is designed and developed by Yukihiro "martz" Matsumoto in mid 1990 in Japan.

3) Why Ruby is known as a language of flexibility?
Ruby is known as a language of flexibility because it facilitates its author to alter the programming elements. Some specific parts of the language can be removed or redefined. Ruby does not restrict the user. For example, to add two numbers, Ruby allows to use + sign or the word 'plus'. This alteration can be done with Ruby's built-in class Numeric.

4) List some features of Ruby?
Ruby has many features. Some of them are listed below.
Object-oriented
Flexible
Dynamic typing and Duck typing
Garbage collector
Keyword arguments

5) Explain some differences between Ruby and Python.
Similarities:
High level language
Support multiple platforms
Use interactive prompt called irb
Server side scripting language
Differences:
Ruby is fully object oriented while Python is not.
Ruby supports EclipseIDE while Python supports multiple IDEs.
Ruby use Mixins while Python doesn't.
Ruby supports blocks, procs and lambdas while Python doesn't.

6) Write the command to get installed Ruby version in your system.
ruby -v

7) What are class libraries in Ruby?
Ruby class libraries contain variety of domain such as thread programming, data types, various domains. Following is a list of domains which has relevant class libraries:
Text processing
CGI Programming
Network programming
GUI programming
XML programming

8) Name some operators used in Ruby.
Operators are a symbol which is used to perform different operations.
Unary operator
Airthmetic operator
Bitwise operator
Logical operator
Ternary operator

9) What is RubyGems in Ruby programming language?
RubyGems provides a standard format for distributing ruby programs and libraries. It works as a package manager for the Ruby programming language.
RubyGems is now a part of the standard library from Ruby version 1.9.

10) What are Ruby variables.
Ruby variables hold data which can be used later in a program. Each variable act as a memory and shas a different name.
There are four types of variables in Ruby:
Local variable
Class variable
Instance variable
Global variable

11) What is the difference between nil and false in Ruby?
nil
false
nil cannot be a value.
false can be a value.
nil is returned where there is no predicate.
in case of a predicate, true or false is returned by a method.
nil is not a boolean data type.
false is a boolean data type.
nil is an object of nilclass.
false is an object of falseclass.

12) Explain Ruby data types.
Ruby data types represent type of data such as text, string, numbers, etc.
There are different data types in Ruby:
Numbers
Strings
Symbols
Hashes
Arrays
Booleans

13) What is the use of load and require in Ruby?
In Ruby, load and require both are used for loading the available code into the current code. In cases where loading the code required every time when changed or every times someone hits the URL, it is suggested to use 'load'.
It case of autoload, it is suggested to use 'require'.

14) Explain Ruby if-else statement.
The Ruby if-else statement is used to test condition. There are various types of statement in Ruby.
if statement
if-else statement
if-else-if (elsif) statement
ternary statement

15) Explain case statement in Ruby.
In Ruby, we use 'case' instead of 'switch' and 'when' instead of 'case'. The case statement matches one statement with multiple conditions just like a switch statement in other languages.

More about Ruby:

No comments:

Post a Comment