热门面试题与答案和在线测试
面向面试准备、在线测试、教程与实战练习的学习平台

通过聚焦学习路径、模拟测试和面试实战内容持续提升技能。

WithoutBook 将分主题面试题、在线练习测试、教程和对比指南整合到一个响应式学习空间中。

面试准备

Ruby On Rails 面试题与答案

Question: What is the purpose of YIELD in Ruby on Rails?
Answer:

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. Lets understand a little bit of background about where YIELD might be useful first. 

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

Developers often write common code in a central file and then they write the custom code in the specific files. Lets 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.

保存以便复习

收藏此条目、标记为困难题,或将其加入复习集合。

打开我的学习资料库
这有帮助吗?

用户评价最有帮助的内容:

版权所有 © 2026,WithoutBook。