Ruby On Rails Interview Questions For Beginners.
List of Ruby On Rails interview questions.
1) Explain what is Mixin in Rails?
Mixin in Ruby offers an alternative to multiple inheritances, using mixin modules can be imported inside other class.
2) Explain how you define Instance Variable, Global Variable and Class Variable in Ruby?
Ruby Instance variable begins with — @
Ruby Class variables begin with — @@
Ruby Global variables begin with — $
3) Explain how you can run Rails application without creating databases?
You can execute your application by uncommenting the line in environment.rb
path=> rootpath conf/environment.rb
config.frameworks = [ action_web_service, :action_mailer, :active_record]
4) Mention what is the difference between the Observers and Callbacks in Ruby on Rails?
Rails Observers: Observers is same as Callback, but it is used when method is not directly associated to object lifecycle. Also, the observer lives longer, and it can be detached or attached at any time. For example, displaying values from a model in the UI and updating model from user input.
Rails Callback: Callbacks are methods, which can be called at certain moments of an object’s life cycle for example it can be called when an object is validated, created, updated, deleted, A call back is short lived. For example, running a thread and giving a call-back that is called when thread terminates
5) Explain what is rake in Rails?
Rake is a Ruby Make; it is a Ruby utility that substitutes the Unix utility ‘make’, and uses a ‘Rakefile’ and ‘.rake files’ to build up a list of tasks. In Rails, Rake is used for normal administration tasks like migrating the database through scripts, loading a schema into the database, etc.
6) Explain how you can list all routes for an application?
To list out all routes for an application you can write rake routes in the terminal.
7) Explain what is sweeper in Rails?
Sweepers are responsible for expiring or terminating caches when model object changes.
8) Mention the log that has to be seen to report errors in Ruby Rails?
Rails will report errors from Apache in the log/Apache.log and errors from the Ruby code in log/development.log.
9) Explain what is the difference between Dynamic and Static Scaffolding?
It automatically creates the entire content and user interface at runtime
It enables to generation of new, delete, edit methods for the use in application
It does not need a database to be synchronized
It requires manual entry in the command to create the data with their fields
It does not require any such generation to take place
It requires the database to be migrated
10) Mention what is the function of garbage collection in Ruby on Rails?
The functions of garbage collection in Ruby on Rails includes
It enables the removal of the pointer values which is left behind when the execution of the program ends
It frees the programmer from tracking the object that is being created dynamically on runtime
It gives the advantage of removing the inaccessible objects from the memory, and allows other processes to use the memory
11) Mention what is the difference between redirect and render in Ruby on Rails?
Redirect is a method that is used to issue the error message in case the page is not issued or found to the browser. It tells the browser to process and issue a new request.
Render is a method used to make the content. Render only works when the controller is being set up properly with the variables that require to be rendered.
12) Mention what is the purpose of RJs in Rails?
13) Explain what is Polymorphic Association in Ruby on Rails?
Polymorphic Association allows an ActiveRecord object to be connected with Multiple ActiveRecord objects. A perfect example of Polymorphic Association is a social site where users can comment on anywhere whether it is videos, photos, links, status updates, etc. It would be not feasible if you have to create an individual comment like photos_comments, videos_comment and so on.
14) Mention what is the difference between calling super() and super call?
super(): A call to super() invokes the parent method without any arguments, as presumably expected. As always, being explicit in your code is a good thing.
super call: A call to super invokes the parent method with the same arguments that were passed to the child method. An error will, therefore, occur if the arguments passed to the child method don’t match what the parent is expecting.
15) Explain about Dig, Float, and Max?
Float class is used whenever the function changes constantly.
Dig is used whenever you want to represent a float in decimal digits.
Max is used whenever there is a huge need of Float.
16) Explain how can we define Ruby regular expressions?
Ruby regular expression is a special sequence of characters that helps you match or find other strings. A regular expression literal is a pattern between arbitrary delimiters or slashes followed by %r.
17) Explain what is the defined operator?
Define operator states whether a passed expression is defined or not. If the expression is defined, it returns the description string and if it is not defined it returns a null value.
18) List out the few features of Ruby?
No Indentation – Indentation isn’t as strict as it is in python. Your code should work fine if indentation is off, but may not be maintainable or readable to another developer.
Case sensitive – The uppercase and lowercase letters are distinct
Comments – Anything followed by an unquoted #, to the end of the line on which it appears, is ignored by the interpreter
Statement delimiters– Multiple statements on one line must be separated by semicolons, but they are not required at the end of a line.