Ruby Core Interview Questions with Answers Page I
From freshersonline.com
1. What is the use of load and require in Ruby?
A method that loads and processes the Ruby code from a separate file, including whatever
classes, modules, methods, and constants are in that file into the current scope. load is
similar, but rather than performing the inclusion operation once, it reprocesses the code
every time load is called.
2. How is visibility of methods changed in Ruby?
By applying the access modifier : Public , Private and Protected acces Modifier
3. How is an iterator handled in Ruby?
Iterator is handled using keyword 'each' in ruby.
For example
$no=[1,2,3]
then we can use iterator as
$no.each do |l|
puts l
end
Above prints the values of an array $no which is accomplished using iterator.
4. What is the scope of a local variable in Ruby?
A new scope for a local variable is introduced in the toplevel, a class (module) definition, a method defintion.
In a procedure block a new scope is introduced but you can access to a local variable outside the block.
The scope in a block is special because a local variable should be localized in Thread and Proc objects.
while, until, and for are control structures and the scope is shared with the outside of these structures.
loop is a method and the appended block introduces a new scope.
5. What are the looping structures available in Ruby?
for..in
untill..end
while..end
do..end
6. What are the operators available in Ruby?
Something that’s used in an expression to manipulate objects such as + (plus), - (minus), * (multiply), and / (divide).
You can also use operators to do comparisons,such as with <, >, and &&.
7. How is class methods defined in Ruby?
def self.methodname
.......
.......
end
or
def classname.methodname
.......
.......
end
8. What is the log that has to seen to check for an error in ruby rails?
Rails will report errors from Apache in log/apache.log and errors from the Ruby code in log/development.log.
If you're having a problem, do have a look at what these logs are saying. On Unix and Mac OS X you may run
tail -f log/development.log in a separate terminal to monitor your application's execution.
9. What is the Install rail package?
There are several packages that you can download and install. The prebuilt Rails installer called Install rail
which currently is only for Windows
10. Where does the start_tabnav gets informations for tabs rendering in ruby rail?
The main Symbol let the start_tabnav method know to look for a special MainTabnav class where all the magic happens.
11. What is the use of super in ruby rails?
Ruby uses the super keyword to call the superclass implementation of the current method
