Professional Ruby Interview Questions & Answers:
1. Explain the difference between nil and false in ruby?
False is a boolean datatype
Nil is not a data type
2. Explain 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
3. What is the use of load and require in ruby?
Reuire() 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() performs the inclusion operation once, it reprocesses the code every time load is called.
4. What is the use of super in Ruby Rails?
► Ruby uses the super keyword to call the superclass implementation of the current method.
► Within the body of a method, calls to super acts just like a call to that original method.
► The search for a method body starts in the superclass of the object that was found to contain the original method.
def url=(addr)
super (addr.blank? || addr.starts_with?('http')) ? addr : http://#{addr}
end
5. Interpolation is a very important process in Ruby, comment.
► Interpolation is the process of inserting a string into a literal.
► You can interpolate a string into a literal by placing a Hash (#) within {} open and close brackets.
► This refers to a new name to by referring to the copy of the original method.
6. Describe the environment variables present in Ruby.
RUBYOPT
Additional command-line options to Ruby; examined after real command-line options are parsed ($SAFE must be 0).
RUBYLIB
Additional search path for Ruby programs ($SAFE must be 0).
RUBYPATH
With -S option, search path for Ruby programs (defaults to PATH).
RUBYSHELL
Shell to use when spawning a process; if not set, will also check SHELL or COMSPEC. DLN_LIBRARY_PATH Search path for dynamically loaded modules.
RUBYLIB_PREFIX
(Windows only) Mangle the RUBYLIB search path by adding this prefix to each component.
7. Explain the concepts and capabilities of garbage collection feature of Ruby.
► 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.
8. Describe class libraries in Ruby.
► The Ruby standard library extends the foundation of the Ruby built-in library with classes and abstractions for a variety of programming needs, including network programming, operating system services, threads, and more.
► These classes provide flexible capabilities at a high level of abstraction, giving you the ability to create powerful Ruby scripts useful in a variety of problem domains.
► Ruby on Rails is an open source web application framework for the Ruby programming language.
► It is used with an Agile development methodology that is used by web developers for rapid development.
10. Explain about the programming language ruby?
Ruby is the brain child of a Japanese programmer Matz. He created Ruby. It is a cross platform object oriented language. It helps you in knowing what your code does in your application. With legacy code it gives you the power of administration and organization tasks. Being open source, it did go into great lengths of development.
https://InterviewQuestionsAnswers.ORG.