Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Ruby On Rails Interview Questions and Answers

Ques 71. What is a lambda?

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 72. What are the three levels of method access control for classes and what do they signify? What do they imply about the method?

  • 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 73. Explain what functional testing is in Ruby on Rails.

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
 

Ques 74. What is the purpose of YIELD in Ruby on Rails?

The interpreter essentially invokes a separate piece of code and places it in the location. You might say it is similar to a method calling another method. Let’s understand a little bit of background about where YIELD might be useful first. 

The Rails framework encourages you to write code that is DRY (Don’t Repeat Yourself).

Developers often write common code in a central file and then they write the custom code in the specific files. Let’s say you are building a web application and you want all pages to have a common header, a common footer, the same “Welcome user-name!” message.

You can put all this common code in your application.html.erb file.

<html> .... common page title
.. standard header... 
<body> 
..common page title,
 <%= YIELD %>
..footer code can go here... </body> 
</html>

The rest of the custom code can go in your specific file. Say the page you are creating is the list of articles. Then in your implementation file you would just write the code for pulling in the articles and the final page displayed to the user would be your custom code which will be placed instead of the <%= YIELD %>code in the application.html.erb file.

Is it helpful? Add Comment View Comments
 

Most helpful rated by users:

©2024 WithoutBook