|
|
|
The General Ruby Interview Questions consists the most frequently asked
questions in Ruby. This list of 100+ questions guage your familiarity with the
Ruby. The q&a have been collected over a period of time from various blogs,
forums and other sites
|
1. Ruby Interview Questions and FAQs
|
| 1.1 What is
Ruby?
|
| 1.2 What is
Rails?
|
| 1.3 How
would you create a new ruby rail application?
|
| 1.4 How do
you comment out a block of code?
|
| 1.5 What's
the difference in scope for these two variables: @name and @@name?
|
1.6 What two
delimiters are used for blocks?
|
| 1.7 How do
you capitalize all characters in a string?
|
| 1.8 How do
the following methods differ: @my_string.strip and @my_string.strip! ?
|
| 1.9 What is
the naming conventions for methods that return a boolean result?
|
| 1.10 What
is the difference between nil and false in ruby?
|
1.1 What is Ruby?
|
|
Ruby is a pure object-oriented programming language with a super clean syntax
that makes programming elegant and fun. Ruby successfully combines Smalltalk's
conceptual elegance, Python's ease of use and learning, and Perl's pragmatism.
Ruby originated in Japan in the early 1990s, and has started to become popular
worldwide in the past few years as more English language books and
documentation have become available.
|
1.2 What is Rails?
|
|
Rails is an open source Ruby framework for developing database-backed web
applications. What's special about that? There are dozens of frameworks out
there and most of them have been around much longer than Rails. Why should you
care about yet another framework? What would you think if I told you that you
could develop a web application at least ten times faster with Rails than you
could with a typical Java framework? You can--without making any sacrifices in
the quality of your application! How is this possible? Part of the answer is in
the Ruby programming language. Many things that are very simple to do in Ruby
are not even possible in most other languages. Rails takes full advantage of
this. The rest of the answer is in two of Rail's guiding principles: less
software and convention over configuration. Less software means you write fewer
lines of code to implement your application. Keeping your code small means
faster development and fewer bugs, which makes your code easier to understand,
maintain, and enhance. Very shortly, you will see how Rails cuts your code
burden. Convention over configuration means an end to verbose XML configuration
files--there aren't any in Rails! Instead of configuration files, a Rails
application uses a few simple programming conventions that allow it to figure
out everything through reflection and discovery. Your application code and your
running database already contain everything that Rails needs to know!
|
1.3 How would you create a new ruby rail application?
|
|
To create a new ruby rail application rails my_app cd my_app
|
|
1.4 How do you comment out a block of code?
|
|
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 #
|
1.5 What's the difference in scope for these two variables: @name and @@name?
|
|
@name is an instance variable and @@name is a class variable
|
1.6 What two delimiters are used for blocks?
|
|
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.
|
1.7 How do you capitalize all characters in a string?
|
|
"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.
|
1.8 How do the following methods differ: @my_string.strip and @my_string.strip!
?
|
|
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.
|
1.9 What is the naming conventions for methods that return a boolean result?
|
|
Methods that return a boolean result are typically named with a ending question
mark. For example: def active? return true #just always returning true end
|
1.10 What is the difference between nil and false in ruby?
|
|
False is a boolean datatype Nil is not a data type
|
|