
Our Services
Get 9,000 Interview Questions & Answers in an eBook.

Get it now !!
Send your Resume to 6000 Companies
Ruby Interview Questions & Answers - Learning Mode

Ruby Interview Questions & Answers - Learning Mode

Ruby is a dynamic, reflective, object-oriented, general-purpose programming language. A dynamic, open source programming language with a focus on simplicity and productivity. It has an elegant syntax that is natural to read and easy to write. Ruby is a programming language. It was created 20 years ago by Yukihiro ?Matz? Matsumoto. By most measures of programming language popularity, Ruby ranks among the top ten, though usually as tenth (or so) in popularity, and largely due to the popularity of Rails.

Try Ruby Interview Questions & Answers - Exam Mode

1 2 Next

Sort By : Latest First | Oldest First | By Rating

Ruby Interview Questions & Answers - Learning Mode
Try Ruby Interview Questions & Answers - Exam Mode
Question: What two delimiters are used for blocks?

Answer: Curly braces {?} and ?do???end?
Bonus: coding convention is to use curly braces if the code will fit on one line and ?do???end? syntax if the block contains multiple lines.
Question: How do you comment out a block of code?

Answer: Use =begin and =end.
def my_commented_out_method
You could use successive # signs, but that?s just tedious:
# def my commented_out_method
# end
Question: Explain about environment variables present in ruby?

Question: Explain about Class variable and global variable?

Answer: A class variable starts with an @@ sign which is immediately followed by upper or lower case letter. You can also put some name characters after the letters which stand to be a pure optional. A class variable can be shared among all the objects of a class. A single copy of a class variable exists for each and every given class.
To write a global variable you start the variable with a $ sign which should be followed by a name character. Ruby defines a number of global variables which also incl Source:
Question: What is the use of Destructive Method?

Answer: In ruby, we conventionally attach '!' or '?' to the end of certain method names. The exclamation point (!, sometimes pronounced aloud as "bang!") indicates something potentially destructive, that is to say, something that can change the value of what it touches.?chop!?affects a string directly, but?chop?with no exclamation point works on a copy. Here is an illustration of the difference.
s1 = "forth"
Question: What is the use of load and require in Ruby?

Answer: require 'rake'

will cause ruby to look for one of the files rake.rb or in the
directories listed in $:. The script in bin is called simply rake, not
rake.rb, and so require doesn't even consider it.

load, instead, interpret its argument in a different way: it considers
it to
be the whole basename of the file and doesn't try to add any extension
to it.
So, the line

load 'rake'

will make ruby look for a file called  Source:
Question: Explain about portability?

Answer: Ruby language can be ported to many platforms. Ruby programs can be ported to many platforms without any modification to the source code. This feature made the language very useful and highly used by many programmers worldwide. Some of the platforms used are DOS, UNIX, WINDOWS, etc. Source:
Question: Explain about the defined operator?

Answer: Define operator defines whether a passed expression is defined or not. If the expression is defined it returns the description string or null if the expression is not defined. If a variable is defined it gets initialized. If method_call is defined as true then method also gets defined. This is also the same case with super and yield. Source:
Question: How do you write to STDOUT in Ruby?

Answer: Actually two methods are available:
puts writes with a newline
print writes without a newline
Question: What is the Notation used for denoting class variables in Ruby?

Answer: 1) a constant begins with an uppercase letter and it should not be defined inside a method
2) a local must begin with a lowercase letter or the _ underscore sign
3) a global begins with the $ sign; an uninitialized global has the value of "nil" and also produces a warning. can be reffered anywhere in the program
4) instances begin with the @ sign; an uninitialized instance has the value of "nil" and also produces a warning
5) a class variable begins with double @@ and have to be firs Source:
Question: Explain about Float, Dig and Max?

Max is used whenever there is a huge need of Float.
Dig is used whenever you want to represent a float in decimal digits. Source:
Question: How does ruby deal with extremely large numbers?

Answer: Unlike other programming languages ruby deals with extremely large numbers it doesn?t have any barriers. There is no limit on the extent of limit of number usage. Ruby performs this function with two different classes they are fixnum and bignum. Fixnum represents easily managed small numbers and bignum represents big numbers. Ruby entirely handles the functioning of these two classes which leaves a programmer to concentrate on his arithmetic operations. Source:
Question: How do you capitalize all characters in a string?

Answer: ?this is my string?.upcase
If the string is in a variable:
Note: The method: upcase! is another alternative. See next question regarding methods that end with an exclamation.
Question: What?s the difference in scope for these two variables: @name and @@name?

Answer: @name is an instance variable and @@name is a class variable Source:
Question: How do the following methods differ: @my_string.strip and @my_string.strip! ?

Answer: The strip! method modifies the variable directly. Calling strip (without the !) returns a copy of the variable with the modifications, the original variable is not altered. Source:
Question: Explain about class libraries in ruby?

Answer: Ruby has a strong set of class libraries and it covers from a variety of domains such as thread programming, domains and data types. Also ruby is a new language and it also has additional libraries coming every day. Many of the new languages which do exist have huge libraries because of their age. Source:
Question: Explain about the command line options?

Answer: Ruby`s language is executed from the command line like most of the scripting languages. Programming and behavior language environment can be controlled from the interpreter itself. Some of the commands which are used are as follows ?d, -h, -e prog, -v, -T, -r lib, etc. Source:
Question: Explain about garbage collection feature of ruby?

Question: Explain about ruby names?

Question: What is the naming conventions for methods that return a boolean result?

Answer: Methods that return a boolean result are typically named with a ending question mark.
For example:
def active?
return true #just always returning true

1 2 Next

India News Network
Latest 20 Questions
Cache = 0.046875 Seconds