Monday, March 30, 2009

Ruby Core intervew Questions

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 object-oriented programming features supported by Ruby?
Classes,Objects,Inheritance,Singleton methods,polymorphism(accomplished by over riding and overloading) are some oo concepts supported by ruby. ...
6. What are the looping structures available in Ruby?
for..in
untill..end
while..end
do..end
7. 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 &&.
8. How is class methods defined in Ruby?
def self.methodname
--------
--------
end
or
def classname.methodname
--------
--------
end
9. How is class methods defined in Ruby?
A:def self.methodname
--------
--------
end
or
def classname.methodname
--------
--------
end
10. What is the difference between nil and false in ruby?
False is a boolean datatype Nil is not a data type
11. 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.
12. 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
13. 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.
14. What is the use of super in ruby rails?
Ruby uses the super keyword to call the superclass implementation of the current method
15. 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.
16. 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
17. 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
What is the use of global variable $ in Ruby?
If you declare one variable as global we can access any where, where as class variable visibility only in the class Example
class Test
def h
 $a = 5
 @b = 4
Â
while $a > 0
puts $a
$a= $a - 1
end
end
end
test = Test.new
test.h
puts $a                    # 5
puts @b                   #nil
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.
What's the difference in scope for these two variables: @name and @@name?
@name is an instance variable and @@name is a class variable
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.
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

No comments:

Post a Comment