Without Book Interview Questions and Answers | Online Test | Moct Test
Download Android App in your Android Device from Google Play Store
- Search for "Withoutbook Practice Exam Test" in Mobile/Tablet Play Store
Institute Training Search by Name or Email

Exams Attended

Make Homepage

Bookmark this page

Subscribe Email Address

Ruby On Rails Interview Questions and Answers

Ques 16. Explain a polymorphic association in Ruby on Rails.

Ans. Polymorphic associations allow a model to belong to more than one other model through a single association.


class Picture < ActiveRecord::Base
  belongs_to : imageable, polymorphic: true
end

class Employee < ActiveRecord::Base
  has_many : pictures, as: : imageable
end

class Product < ActiveRecord::Base
  has_many : pictures, as: : imageable
end
  • Here, the class Picture belongs_to both Employee and Product, but does so through a single association rather than through multiple.
  • Be sure to know an appropriate situation to create a polymorphic association, such as creating a comment model associated with multiple other models (articles, photos, etc.). The advantage of using polymorphism here is that it allows you to create a single comment model, rather than separate models for each one (PhotoComment model, ArticleComment model, etc.)

Is it helpful? Add Comment View Comments
Ques 17. What is a Proc?
Ans. Procs, short for procedures, act similar to blocks, but can be saved as variables and reused. Think of them as blocks you can call over and over again on multiple arrays.
Is it helpful? Add Comment View Comments
Ques 18. What is a lambda?
Ans. Lambdas are very similar to procs in terms of functionality. However, they have a few key differences. Lambdas check the number of arguments passed and will return an error if you try to pass the wrong number (while procs set extra variables to nil). The other difference is that lambdas can handle a return function, whereas procs will return an error.
Is it helpful? Add Comment View Comments
Ques 19. What are the three levels of method access control for classes and what do they signify? What do they imply about the method?
Ans.
  • Public, protected, and private.

  • Public methods can be called by all objects and subclasses of the class in which they are defined in.

  • Protected methods are only accessible to objects within the same class.

  • Private methods are only accessible within the same instance.

  • Be able to explain why this does (or doesn’t matter), and when you would want to set a method as private.
Is it helpful? Add Comment View Comments
Ques 20. Explain what functional testing is in Ruby on Rails.
Ans. Functional testing in Rails allows you to test the response of  various actions contained in a controller. Using the Rails default test library, mini test, functional tests use a collection of assert statements that will tell your testing library to expect a certain response based on a control request passed in (either a get, post, patch, put, head, delete request).
Is it helpful? Add Comment View Comments

Most helpful rated by users:

©2016 WithoutBook