简体   繁体   English

为什么视图代码没有包装在类中?

[英]Why is view code not wrapped inside classes?

This is one of these "Why do things work in a certain way" questions. 这是这些“为什么事情以某种方式起作用”的问题之一。

Since Rails is a purely object oriented language, controller code, model code, helper code, migration code, etc. is wrapped inside classes. 由于Rails是纯粹的面向对象语言,因此控制器代码,模型代码,帮助程序代码,迁移代码等被包装在类中。 But not view code. 但不查看代码。

So I was wondering: how does Rails know that view code belongs to the Active View class ? 所以我想知道:Rails如何知道视图代码属于Active View类 How does that work internally? 内部如何运作?

All Ruby files run inside of a class, just run a file that contains this: 所有Ruby文件都在类内部运行,只需运行包含以下内容的文件:

puts self.class.name

and you'll see that your code is wrapped in an Object class when it executes. 并且您会看到代码在执行时被包装在Object类中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM