Ruby Interview Questions with Answers Page I


Jump to: navigation, search

Interview Question Home

1.What is the use of load and require in ruby?

Ans. 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.What function converts all HTML special symbols to HTML entities in ruby?

Ans. This function ae_some_html converts all HTML special symbols to HTML entities

3. Where does the start_tabnav gets informations for tabs rendering in ruby rail?

Ans. <%= start_tabnav :main %>

The :main Symbol let the start_tabnav method know to look for a special MainTabnav class where all the magic happens.

4. What is the use of global variable $ in Ruby?

Ans. If you declare one variable as global we can access any where, as class variable.

5. What is the scope of a local variable in Ruby?

Ans. 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.

6. What is the log that has to seen to check for an error in ruby rails?

Ans. 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.

Personal tools