What Is Ruby?
What Is Ruby Class?
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
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
end
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?
#eql?
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