25+ [ SURE SHOT ] Ruby On Rails Interview Questions & Answers
Ruby Rails Interview Questions and Answers

25+ [ SURE SHOT ] Ruby On Rails Interview Questions & Answers

Last updated on 04th Jul 2020, Blog, Interview Questions

About author

Sanjay (Sr Technical Architect )

High level Domain Expert in TOP MNCs with 8+ Years of Experience. Also, Handled Around 20+ Projects and Shared his Knowledge by Writing these Blogs for us.

(5.0) | 15212 Ratings 1960

These Ruby Rails Interview Questions have been designed specially to get you acquainted with the nature of questions you may encounter during your interview for the subject of Ruby Rails . As per my experience good interviewers hardly plan to ask any particular question during your interview, normally questions start with some basic concept of the subject and later they continue based on further discussion and what you answer.we are going to cover top 100 Ruby Rails  Interview questions along with their detailed answers. We will be covering Ruby Rails  scenario based interview questions, Ruby Rails  interview questions for freshers as well as Ruby Rails  interview questions and answers for experienced. 

1) Explain what Ruby on Rails?

Ans:

  • Ruby: It is an object oriented programming language inspired by PERL and PYTHON.
  • Rails: It is a framework used for building web application

2) Explain what are class libraries in Ruby?

Ans:

Class libraries in Ruby consist of a variety of domains, such as data types, thread programming, various domains, etc.

3) Mention what is the naming convention in Rails?

Ans:

  • Variables: For declaring Variables, all letters are lowercase, and words are separated by underscores
  • Class and Module: Modules and Classes uses MixedCase and have no underscore; each word starts with a uppercase letter
  • Database Table: The database table name should have lowercase letters and underscore between words, and all table names should be in the plural form for example invoice_items
  • Model: It is represented by unbroken MixedCase and always have singular with the table name
  • Controller: Controller class names are represented in plural form, such that OrdersController would be the controller for the order table.

4) Explain what is “Yield” in Ruby on Rails?

Ans:

A Ruby method that receives a code block invokes it by calling it with the “Yield”.

5) Explain what is ORM (Object-Relationship-Model) in Rails?

Ans:

ORM or Object Relationship Model in Rails indicate that your classes are mapped to the table in the database, and objects are directly mapped to the rows in the table.

6) Mention what the difference is between false and nil in Ruby?

Ans:

In Ruby False indicates a Boolean datatype, while Nil is not a data type, it has an object_id 4.

7) Mention what are the positive aspects of Rails?

Ans:

Rails provides many features like

  • Meta-programming: Rails uses code generation but for heavy lifting it relies on meta-programming. Ruby is considered as one of the best languages for Meta-programming.
  • Active Record: It saves objects to the database through Active Record Framework. The Rails version of Active Record identifies the column in a schema and automatically binds them to your domain objects using metaprogramming
  • Scaffolding: Rails have an ability to create scaffolding or temporary code automatically
  • Convention over configuration: Unlike other development framework, Rails does not require much configuration, if you follow the naming convention carefully
  • Three environments: Rails comes with three default environment testing, development, and production.
  • Built-in-testing: It supports code called harness and fixtures that make test cases to write and execute.

8) Explain what is the role of sub-directory app/controllers and app/helpers?

Ans:

  • App/controllers: A web request from the user is handled by the Controller. The controller subdirectory is where Rails looks to find controller classes
  • App/helpers: The helper’s subdirectory holds any helper classes used to assist the view, model and controller classes.

9) Mention what is the difference between String and Symbol?

Ans:

They both act in the same way only they differ in their behaviors which are opposite to each other. The difference lies in the object_id, memory and process tune when they are used together. Symbol belongs to the category of immutable objects whereas Strings are considered as mutable objects.

10) Explain how Symbol is different from variables?

Ans:

Symbol is different from variables in following aspects

  • It is more like a string than variable
  • In Ruby string is mutable but a Symbol is immutable
  • Only one copy of the symbol requires to be created
  • Symbols are often used as the corresponding to enums in Ruby

11) Explain what is Rails Active Record in Ruby on Rails?

Ans:

Rails active record is the Object/Relational Mapping (ORM) layer supplied with Rails. It follows the standard ORM model as

  • Table map to classes
  • Rows map to objects
  • Columns map to object attributes

12) Explain how Rails implements Ajax?

Ans:

Ajax powered web page retrieves the web page from the server which is new or changed unlike other web-page where you have to refresh the page to get the latest information.

Rails triggers an Ajax Operation in following ways

  • Some trigger fires: The trigger could be a user clicking on a link or button, the users inducing changes to the data in the field or on a form
  • Web client calls the server: A Java-script method, XMLHttpRequest, sends data linked with the trigger to an action handler on the server. The data might be the ID of a checkbox, the whole form or the text in the entry field
  • Server does process: The server side action handler does something with the data and retrieves an HTML fragment to the web client
  • Client receives the response: The client side JavaScript, which Rails generates automatically, receives the HTML fragment and uses it to update a particular part of the current

13) Mention how you can create a controller for the subject?

Ans:

To create a controller for subject you can use the following command

C:\ruby\library> ruby script/generate controller subject

14) Mention what is Rails Migration?

Ans:

Rails Migration enables Ruby to make changes to the database schema, making it possible to use a version control system to leave things synchronized with the actual code.

15) List out what Rails Migration can do?

Ans:

Rails Migration can do following things

  • Create table
  • Drop table
  • Rename table
  • Add column
  • Rename column
  • Change column
  • Remove column and so on

16) Mention what is the command to create a migration?

Ans:

To create migration command includes

C:\ruby\application>ruby script/generate migration table_name

17) Explain when self.up and self.down method is used?

Ans:

When migrating to a new version, self.up method is used while self.down method is used to roll back my changes if needed.

18) Mention what is the role of Rails Controller?

Ans:

The Rails controller is the logical center of the application. It facilitates the interaction between the users, views, and the model. It also performs other activities like

  • It is capable of routing external requests to internal actions. It handles URL extremely well
  • It regulates helper modules, which extend the capabilities of the view templates without bulking of their code
  • It regulates sessions; that gives users the impression of an ongoing interaction with our applications

19) Mention what is the difference between Active support’s “HashWithIndifferent” and Ruby’s “Hash” ?

Ans:

The Hash class in Ruby’s core library returns value by using a standard “= =” comparison on the keys. It means that the value stored for a symbol key cannot be retrieved using the equivalent string. While the HashWithIndifferentAccess treats Symbol keys and String keys as equivalent.

20) Explain what is Cross-Site Request Forgery (CSRF) and how Rails is protected against it?

Ans:

CSRF is a form of attack where a hacker submits a page request on your behalf to a different website, causing damage or revealing your sensitive data. To protect from CSRF attacks, you have to add “protect_from_forgery” to your ApplicationController. This will cause Rails to require a CSRF token to process the request. CSRF token is given as a hidden field in every form created using Rails form builders.

    Subscribe For Free Demo

    21) Explain what is Mixin in Rails?

    Ans:

    Mixin in Ruby offers an alternative to multiple inheritances, using mixin modules can be imported inside another class.

    22) Explain how you define Instance Variable, Global Variable and Class Variable in Ruby?

    Ans:

    • Ruby Instance variable begins with — @
    • Ruby Class variables begin with — @@
    • Ruby Global variables begin with — $

    23) Explain how you can run a Rails application without creating databases?

    Ans:

    You can execute your application by uncommenting the line in environment.rb

    path=> root path config/environment.rb

    config.frameworks = [ action_web_service, :action_mailer, :active_record]

    24) Mention what is the difference between the Observers and Callbacks in Ruby on Rails?

    Ans:

    • Rails Observers: Observers is the same as Callback, but it is used when the method is not directly associated with the 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 the 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

    25) Explain what is rake in Rails?

    Ans:

    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.

    26) Explain how you can list all routes for an application?

    Ans:

    To list out all routes for an application you can write rake routes in the terminal.

    27) Explain what is sweeper in Rails?

    Ans:

    Sweepers are responsible for expiring or terminating caches when model objects change.

    28) Mention the log that has to be seen to report errors in Ruby Rails?

    Ans:

    Rails will report errors from Apache in the log/Apache.log and errors from the Ruby code in log/development.log.

    29) Explain what is the difference between Dynamic and Static Scaffolding?

    Ans:

    Dynamic ScaffoldingStatic Scaffolding
    It automatically creates the entire content and user interface at runtimeIt enables to generation of new, delete, edit methods for the use in applicationIt does not need a database to be synchronizedIt requires manual entry in the command to create the data with their fieldsIt does not require any such generation to take placeIt requires the database to be migrated

    30) Mention what is the function of garbage collection in Ruby on Rails?

    Ans:

    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
    Course Curriculum

    Best Ruby on Rails Training from Industry Experts Trainers

    • Instructor-led Sessions
    • Real-life Case Studies
    • Assignments
    Explore Curriculum

    31) Mention what is the difference between redirect and render in Ruby on Rails?

    Ans:

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

    32) Mention what is the purpose of RJs in Rails?

    Ans:

    RJs is a template that produces JavaScript which is run in an eval block by the browser in response to an AJAX request. It is sometimes used to define the JavaScript, Prototype and helpers provided by Rails.

    33) Explain what the Polymorphic Association in Ruby on Rails?

    Ans:

    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 a video, photos, link, status updates etc. It would be not feasible if you have to create an individual comment like photos_comments, videos_comment and so on.

    34) Mention what are the limits of Ruby on Rails?

    Ans:

    Ruby on Rails has been designed for creating a CRUD web application using MVC. This might make Rails not useful for other programmers. Some of the features that Rails does not support include

    • Foreign key in databases
    • Linking to multiple data-base at once
    • Soap web services
    • Connection to multiple data-base servers at once

    35) Mention what is the difference between calling super() and super call?

    Ans:

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

    36) Explain about Dig, Float and Max?

    Ans:

    • 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 for Float.

    37) Explain how we can define Ruby regular expressions?

    Ans:

    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.

    38) Explain what is the defined operator?

    Ans:

    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.

    39) List out the few features of Ruby?

    Ans:

    • Free format – You can start writing from program from any line and column
    • 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.

    40) Mention the types of variables available in Ruby Class?

    Ans:

    Types of variables available in Ruby Class are,

    • Local Variables
    • Global Variables
    • Class Variables
    • Instance Variables

    41) Explain how you can declare a block in Ruby?

    Ans:

    In Ruby, the code in the block is always enclosed within braces ({}).  You can invoke a block by using “yield statement”.

    42) Explain what is the difference between put and putc statements?

    Ans:

    Unlike the puts statement, which outputs the entire string onto the screen. The Putc statement can be used to output one character at a time.

    43) Explain what a class library is in Ruby?

    Ans:

    Ruby class libraries consist of a variety of domains, such as thread programming, data types, various domains, etc. These classes give flexible capabilities at a high level of abstraction, giving you the ability to create powerful Ruby scripts useful in a variety of problem domains. The following domains which have relevant class libraries are,

    • GUI programming
    • Network programming
    • CGI Programming
    • Text processing

    44) In Ruby, it explains about the defined operator?

    Ans:

    The defined operator tells whether a passed expression is defined or not.  If the expression is not defined, it gives null, and if the expression is defined it returns the description string.

    45) Mention what is the difference in scope for these two variables: @@name and @name?

    Ans:

    The difference in scope for these two variables is that:

    • @@name is a class variable
    • @name is an instance variable

    46) Mention what is the syntax for Ruby collect Iterator?

    Ans:

    The syntax for Ruby collect Iterator collection = collection.collect.

    47) In Ruby code, often it is observed that coder uses a shorthand form of using an expression like array.map(&:method_name) instead of array.map { |element| element.method_name }. How does this trick actually work?

    Ans:

    When a parameter is passed with “&” in front of it. Ruby will call to_proc on it in an attempt to make it usable as a block.  So, symbol to_Proc will invoke the method of the corresponding name on whatever is passed to it. Thus helping our shorthand trick to work.

    48) Explain what is Interpolation in Ruby?

    Ans:

    Ruby Interpolation is the process of inserting a string into a literal.  By placing a Hash (#) within {} open and close brackets, one can interpolate a string into the literal.

    49) Mention what is the Notation used for denoting class variables in Ruby?

    Ans:

    In Ruby,

    • A constant should begin with an uppercase letter, and it should not be defined inside a method
    • A local must begin with the _ underscore sign or a lowercase letter
    • A global variable should begin with the $ sign. An uninitialized global has the value of “nil” and it should raise a warning. It can be referred anywhere in the program.
    • A class variable should begin with double @@ and have to be first initialized before being used in a method definition

    50) Mention what is the difference between Procs and Blocks?

    Ans:

    The difference between Procs and Blocks,

    • Block is just the part of the syntax of a method while proc has the characteristics of a block
    • Procs are objects, blocks are not
    • At most one block can appear in an argument list
    • Only block is not able to be stored into a variable while Proc can
    Course Curriculum

    Get In-Depth Knowledge in Ruby on Rails Certification Course

    Weekday / Weekend BatchesSee Batch Details

    51) Mention what is the difference between a single quote and double quote?

    Ans:

    A single-quoted strings don’t process ASCII escape codes, and they don’t do string interpolation.

    52) Mention what is the difference between a gem and a plugin in Ruby?

    Ans:

    • Gem: A gem is a just ruby code. It is installed on a machine, and it’s available for all ruby applications running on that machine.
    • Plugin: Plugin is also ruby code, but it is installed in the application folder and only available for that specific application.

    53) Mention what is the difference between extend and include?

    Ans:

    The “include” makes the module’s methods available to the instance of a class, while “extend” makes these methods available to the class itself.

    54. Walk me through the request/response cycle for accessing a list of articles in a blogging application?

    Ans:

    The user clicks a button and a GET request is made to the URL,/articles. The web server receives this request. Rails then executes the corresponding controller action, #index, based on URL/controller mapping in routes.rb.

    The controller calls Article.all which loads a collection of articles from the database via the Article model. This collection is assigned to an instance variable.

    A view is rendered to the requesting user which interpolates the instance variable values to display the list of articles.

    55.  Everything (almost) is an object in Ruby. Please explain

    Ans:

    In object-oriented programming, an object is an instance of a class. In Ruby, all classes are instances of the class Class.

    For example:

    7.class => Fixnum

    7.class.class => Class

    A few things are not objects like blocks, methods, and conditional statements (i.e.: if, else).

    This question is asked to see if you understand that most things in Ruby behave similarly, which makes Ruby easier to pick up than other languages.

    56. Is Ruby statically or dynamically typed?

    Ans:

    Ruby is dynamically typed. This is why you can change the type of a variable on the fly.

    In Ruby, the following lines of code, run one after the other, do not throw an error.

    x = 1

    x = “foo”

    57. Tell me about getters and setters in Ruby

    Ans:

    A getter allows accessing an instance variable. A setter allows setting an instance variable.

    It’s possible to manually define getter and setter methods.

    But Ruby provides three accessor methods that do the same thing and are cleaner: attr_reader (getter), attr_writer (setter), and attr_accessor (setter and getter).

    58. What happens when you call a method in Ruby?

    Ans:

    A message containing the method’s name is sent to the object. If that method exists on the object, the object calls it.

    This is more apparent if considering Ruby’s send method.

    • obj.hello # => ‘hello’
    • obj.send(:hello) # => ‘hello’

    59. How can you list all routes in an app?

    Ans:

    $ rake routes

    It’s also possible to append to this, | grep <keyword>, to filter returned routes.

    60. What is a Gemfile?

    Ans:

    A Gemfile is where we specify dependencies for a Ruby application. It is located in the project’s root directory.

    61. What is Gemfile.lock?

    Ans:

    It contains records of exact versions of gems installed. This is so the same versions can be installed if another machine clones the project.

    In contrast, specifying a gem in a Gemfile without pegging to a specific version will just install the latest version of a gem.

    62. What are some Rails design patterns you’ve used?

    Ans:

    There are a number of design patterns in Rails including service objects, value objects, form objects, query objects, view objects, policy objects, and decorators.

    Digging into each one is the topic of a full post but here is a with examples.

    63. How does Rails manage database state?

    Ans:

    The developer manually generates and adds instructions to migration files.

    These instruct ActiveRecord how to modify the existing database state. For this reason, deleting or modifying previous migrations can put the database into a bad state and is not recommended.

    Manually creating migration files is in contrast to other frameworks like Django, where the end state of the database is specified and then migrations are auto-generated to make the required changes.

    64. What is the difference between count, length, and size?

    Ans:

    • count: Executes an SQL query to count the number of records. This is useful if the number of records may have changed in the DB vs. memory.
    • length: Returns the number of items in a collection in memory. It’s lighter weight than count because no database transaction is performed. It can also be used to count characters in a string.
    • size: This is an alias for length and does the same thing.

    65. How have you implemented authorization in the past?

    Ans:

    Authorization (not to be confused with authentication) pertains to allowing different types of users different levels of access in an app. It’s useful when there are lots of types of users with differing levels of access.

    A few gems like Pundit and CanCanCan implement authorization.

    66. What are callbacks?

    Ans:

    “Callback” is a misleading term. They are hooks into the object lifecycle on which you can execute methods.

    A number of callbacks exist around creating, updating, and destroying an object such as before_validation, after_save, and after_destroy.

    They are useful for conditional logic like creating an associated Contact record when a User record is created.

    67. When would you use a before_save vs. after_save callback?

    Ans:

    Updating an object after it’s been saved requires an additional database transaction to persist the update. So, if you are updating an object’s attribute, a before_save callback is more efficient.

    But sometimes information does exist on the object until it’s persisted (i.e.: id). So, if an id is required to create an associated record, that would have to be performed in an after_save callback.

    68. What are initializers in Rails?

    Ans:

    : Initializers hold configuration logic and only run when an app is booted. This means the Rails server needs to be restarted if initializers are changed. They exist in the /config/initializers directory.

    69. What is the difference between delete and destroy?

    Ans:

    • delete: Deletes a record.
    • destroy: Deletes a record and executes callbacks.

    The most common callback on destroy in Rails apps is specified on associations in model files. For example, the below destroys related comments when an article is destroyed.

    class Article < < BaseController

     has_many :comments, dependent: :destroy

    end

    70. What is the meaning of “Fat models, skinny controllers”?

    Ans:

    Business logic should exist in models, not controllers. This makes logic easier to unit test and is more reusable.

    Controllers are merely the hands that pass information between views and models.

    This is generally given as advice to new Rails developers. It’s not actually recommended, particularly in large apps.

    Ruby On Rails Sample Resumes! Download & Edit, Get Noticed by Top Employers! Download

    71. What is the meaning of “skinny controllers, skinny models”?

    Ans:

    As a codebase grows, fat models get out of hand, start doing too many things and become unmanageable. Models should handle persistence without being bloated with logic.

    Models can be made skinnier by keeping the single responsibility principle in mind and moving logic out of models, and into other design patterns like service objects.

    72. What is the difference between class methods and instance methods?

    Ans:

    Class methods are available on classes, and instance methods are available on instances (of course).They are typically used for different purposes.

    For a class, Article, an instance method may count the number of words in the body of a specific article. While a class method may count the number of articles by a particular writer across all articles (notice the difference in scope?).

    Class methods are denoted by def self.method_name.

    73. What is a PORO?

    Ans:

    PORO stands for “Plain Old Ruby Object”.

    Although almost everything in Ruby is an object, ActiveRecord tends to use a lot of complex objects. So, the term PORO is typically to stress a small, simple object used to support business logic.

    74. Does Ruby allow multiple inheritances?

    Ans:

    Ruby does not allow inheriting from more than one parent class, but it does allow module mixins with include and extend.

    75. Is Ruby strongly or weakly typed?

    Ans:

    Ruby is strongly typed. An error will be thrown if you try to calculate “hello” + 3.

    In contract, JavaScript is weakly typed and would simply evaluate the same calculation to “hello3”.

    76. What frameworks have you used for backgrounding jobs?

    Ans:

    • Delayed::Job: Easy to set up and use. Queues are stored in a database table. If the same database is used for Delayed::Job and production, then a large number of jobs could turn the database into a bottleneck.
    • Sidekiq: Uses Redis to queue jobs. Redis is an in-memory data store so it’s very fast. Sidekiq adds complexity to infrastructure because Redis needs to be added.
    • Sucker Punch: Runs as a Ruby process and keeps all jobs in memory. Jobs are lost if the process crashes. Not recommended for critical tasks.

    77. How to declare a constructor on a Ruby class?

    Ans:

    A constructor is defined via an initialize method which is called when a new instance of a class is initialized. Defining this method is not required. It’s often used to provide attribute values on new instances.

    78. What logic goes into a helper?

    Ans:

    Helper logic should support views only.

    A good candidate for a helper is date formatting logic required in several different views.

    79. What is ActiveRecord?

    Ans:

    Active Record is an ORM (object-relational mapping) that maps models to database tables. It simplifies setting up an app because we no longer have to write SQL directly to load, save, or delete objects.

    It also provides some protection against SQL injection.

    80. When do we use “self” in Ruby?

    Ans:

    • Use self when defining and calling class methods.
    • In a class, self refers to the current class so it’s required when a class method calls another class method.
    • self.class.method is required when an instance calls a class method.

    81. What is Rack?

    Ans: Rack is an API sitting between the web server and Rails. It allows plugging in and swapping frameworks like Rails with Sinatra, or web servers like Unicorn with Puma.

    82. What is MVC?

    Ans:

    MVC (Model-View-Controller) is a software design pattern that Rails is built around. It splits the handling of information into three pieces.

    The model manages data and logic. The view displays information. The controller takes input and prepares data for a model or view

    MVC-model

    83. What is a block in Ruby?

    Ans:

    A block is the code between two braces, {…}, or between do and end. You’re passing a block every time you call .each.

    Blocks have their own scope and variables only defined inside a block are not accessible outside. But variables defined outside a block can be modified inside a block.

    {|x| puts x} # a block

    84. What is the difference between a proc and a lambda?

    Ans:

    Both procs and lambdas are stored blocks but syntax and behavior differs slightly.

    A lambda returns from itself but a proc returns from the method it’s inside.

    Notice that method_proc returns 1 because calling the proc ends execution within the method.

    85. What is yielded in Ruby?

    Ans:

    yield accesses a block passed to a method. It’s typically used in layout files in a Rails application.

    Notice the “its me” is printed when yield is called.

    86. What is content_for for?

    Ans:

    It allows defining and rendering content in views. This is useful for defining content in one place and rendering it in many.

    87. What is the difference between Hash and JSON?

    Ans:

    Hash is a Ruby class, a collection of key/value pairs that allows accessing values by keys.

    JSON is a string in a specific format for sending data.

    88. What is an Active Job?

    Ans:

    Allows creating background jobs and queuing them on a variety of back ends like Delayed::Job or Sidekiq.

    It’s typically used to execute code that doesn’t need to be executed in the main web thread. A common use case is sending notification emails to users.

    89. What do you like about Rails?

    Ans:

    I’ve used a number of web frameworks and nothing is as fast for building an MVP as Rails. A few things I like in particular:

    • It’s fun. Being able to do Time.now + 5.days or obj.nil? just makes me happy.
    • The community is very helpful and it is easy to find examples/documentation.
    • Convention over configuration means you generally know where to find things when walking into a new large codebase. Especially in comparison to other frameworks that prefer configuration like Django.

    90. What do you dislike about Rails?

    Ans:

    Machine learning libraries are poorly developed or non-existent.

    91. What is your favorite Ruby gem?

    Ans: One that every Rails developer knows, Devise. It makes setting up something complex like authentication a two-minutes job.

    92. What is Spring?

    Ans:

    Spring is an application preloader. It keeps the application running in the background so booting is not required any time you run a migration or rake task.

    93. What is the asset pipeline?

    Ans:

    It’s a framework that prepares JavaScript and CSS for the browser.

    94. How have you managed authentication in Rails?

    Ans:

    Devise.

    95. What is the splat operator?

    Ans:

    Splat is used when you don’t want to specify the number of arguments passed to a method in advance. Ruby has two splat operators, the single splat and double splat.

    The single splat works as you’d expect:

    The double splat is like the single splat but it takes key/values as arguments.

    96. What is the difference between include and extend?

    Ans:

    Both are mixins that allow injecting code from another module.

    But include allows accessing that code via class methods, while extend allows accessing that code via instance methods.

    97. What is the difference between load and require?

    Ans:

    • load runs another file, even if it’s already in memory.
    • require will only run another file once, no matter how many times you require it.

    98. What is the difference between a class and a module?

    Ans:

    • A class has attributes and methods. You can create an instance of a class.
    • A module is just a collection of methods and constants, which you can mixin with another module or class.

    99. What’s a scope?

    Ans:

    A scope is ActiveRecord query logic that you can define inside a model and call elsewhere.

    Defining a scope can be useful rather than duplicating the same logic in many places in the app.

    # an example scope

    • class Post
    • scope :active_posts, -> { where(active:true) }
    • end

    100. What is the difference between class and instance variables?

    Ans:

    Instance variables denoted by @, are associated with an instance of a class. Changing the value of an attribute on one instance has no effect on the variable for another instance.

    Class variables denoted by @, are less intuitive. They are shared across all instances of a class. So, changing the variable on one instance affects that variable for all instances.

    Notice how the class variable can be updated by any instance of the class.

    Are you looking training with Right Jobs?

    Contact Us
    Get Training Quote for Free