CoolInterview.com - World's Largest Collection of Interview Questions & Answers, FAQs, queries, sample papers, exam papers, dumps, what, why, how, where, when questions
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
COOLINTERVIEW.COM PROGRAMMING LANGUAGES INTERVIEW QUESTIONS RUBY INTERVIEW QUESTIONS 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.
Source: CoolInterview.com
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"
s1.chop!?
s2=s1.chop
Source: CoolInterview.com
Question: How do you comment out a block of code?

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

Answer: Following are some of the environment variables used to control the behavior programming of ruby. While programming ENV object lists some of the current variables. RUBYLIB path searches for libraries. Make sure that you separate each path with colons. RUBYOPT passes command line options to Ruby interpreter. There are many more which can be obtained by searching the huge pool of library. Source: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
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 rake.so 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: CoolInterview.com
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
Source: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
Question: Explain about Float, Dig and Max?

Answer: Float class is used whenever the function changes constantly. It acts as a sub class of numeric. They represent real characters by making use of the native architecture of the double precision floating point.
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: CoolInterview.com
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: CoolInterview.com
Question: How do you capitalize all characters in a string?

Answer: ?this is my string?.upcase
If the string is in a variable:
@my_string.upcase
Note: The method: upcase! is another alternative. See next question regarding methods that end with an exclamation.
Source: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
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: CoolInterview.com
Question: Explain about methods?

Answer: Methods in ruby basically perform two functions, named operation and the code present in the class which does a specific function. In Ruby all your algorithms live in methods which inturn is present on objects. Ruby does not have any provision for functions. Code present in Ruby is always a method of some object. Behind the scenes ruby gives you the flexibility to work with methods as functions if you are considering working with other languages. Source: CoolInterview.com
Question: Explain about garbage collection feature of ruby?

Answer: Ruby is an object oriented language and every object oriented language tends to allocate many objects during execution of the program. Ruby deletes unallocated and unused objects automatically. This feature can be controlled by applying proper syntax and program through ruby. Source: CoolInterview.com
Question: Explain about ruby names?

Answer: Classes, variables, methods, constants and modules can be referred by ruby names. When you want to distinguish between various names you can specify that by the first character of the name. Some of the names are used as reserve words which should not be used for any other purpose. A name can be lowercase letter, upper case letter, number, or an underscore, make sure that you follow the name by name characters. Source: CoolInterview.com

1 2 Next



India News Network
Latest 20 Questions
Payment of time- barred debt is: (a) Valid (b) Void (c) Illegal (d) Voidable
Consideration is defined in the Indian Contract Act,1872 in: (a) Section 2(f) (b) Section 2(e) (c) Section 2(g) (d) Section 2(d)
Which of the following is not an exception to the rule, "No consideration, No contract": (a) Natural love and affection (b) Compensation for involuntary services (c) Completed gift (d) Agency
Consideration must move at the desire of: (a) The promisor (b) The promisee (c) The promisor or any other party (d) Both the promisor and the promisee
An offer which is open for acceptance over a period of time is: (a) Cross Offer (b) Counter Offer (c) Standing Offer (d) Implied Offer
Specific offer can be communicated to__________ (a) All the parties of contract (b) General public in universe (c) Specific person (d) None of the above
_________ amounts to rejection of the original offer. (a) Cross offer (b) Special offer (c) Standing offer (d) Counter offer
A advertises to sell his old car by advertising in a newspaper. This offer is caleed: (a) General Offer (b) Special Offer (c) Continuing Offer (d) None of the above
In case a counter offer is made, the original offer stands: (a) Rejected (b) Accepted automatically (c) Accepted subject to certain modifications and variations (d) None of the above
In case of unenforceable contract having some technical defect, parties (a) Can sue upon it (b) Cannot sue upon it (c) Should consider it to be illegal (d) None of the above
If entire specified goods is perished before entering into contract of sale, the contract is (a) Valid (b) Void (c) Voidable (d) Cancelled
______________ contracts are also caled contracts with executed consideration. (a) Unilateral (b) Completed (c) Bilateral (d) Executory
A offers B to supply books @ Rs 100 each but B accepts the same with condition of 10% discount. This is a case of (a) Counter Offer (b) Cross Offer (c) Specific Offer (d) General Offer
_____________ is a game of chance. (a) Conditional Contract (b) Contingent Contract (c) Wagering Contract (d) Quasi Contract
There is no binding contract in case of _______ as one's offer cannot be constructed as acceptance (a) Cross Offer (b) Standing Offer (c) Counter Offer (d) Special Offer
An offer is made with an intention to have negotiation from other party. This type of offer is: (a) Invitation to offer (b) Valid offer (c) Voidable (d) None of the above
When an offer is made to the world at large, it is ____________ offer. (a) Counter (b) Special (c) General (d) None of the above
Implied contract even if not in writing or express words is perfectly _______________ if all the conditions are satisfied:- (a) Void (b) Voidable (c) Valid (d) Illegal
A specific offer can be accepted by ___________. (a) Any person (b) Any friend to offeror (c) The person to whom it is made (d) Any friend of offeree
An agreement toput a fire on a person's car is a ______: (a) Legal (b) Voidable (c) Valid (d) Illegal
Cache = 0.125 Seconds