Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
1b9dca54
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1b9dca54
编写于
12月 16, 2014
作者:
A
Abdelkader Boudih
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #18043 from claudiob/minor-autoloading-guides-fixes
Minor typos/fixes to autoloading guide
上级
ecb26b73
4b9f1298
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
8 addition
and
8 deletion
+8
-8
guides/source/constant_autoloading_and_reloading.md
guides/source/constant_autoloading_and_reloading.md
+8
-8
未找到文件。
guides/source/constant_autoloading_and_reloading.md
浏览文件 @
1b9dca54
...
...
@@ -341,7 +341,7 @@ still be "A::B".
The idea of a parent namespace is at the core of the autoloading algorithms
and helps explain and understand their motivation intuitively, but as you see
that metaphor leaks easily. Given an edge case to reason about, take always into
account th
e
by "parent namespace" the guide means exactly that specific string
account th
at
by "parent namespace" the guide means exactly that specific string
derivation.
### Loading Mechanism
...
...
@@ -542,7 +542,7 @@ modulus some additional directory lookups we are going to cover soon.
INFO.
`'Constant::Name'.underscore`
gives the relative path without extension of
the file name where
`Constant::Name`
is expected to be defined.
Let's see how
does Rails autoload
the
`Post`
constant in the
`PostsController`
Let's see how
Rails autoloads
the
`Post`
constant in the
`PostsController`
above assuming the application has a
`Post`
model defined in
`app/models/post.rb`
.
...
...
@@ -585,7 +585,7 @@ file is loaded. If the file actually defines `Post` all is fine, otherwise
### Qualified References
When a qualified constant is missing Rails does not look for it in the parent
namespaces. But there's a caveat:
U
nfortunately, when a constant is missing
namespaces. But there's a caveat:
u
nfortunately, when a constant is missing
Rails is not able to say if the trigger was a relative or qualified reference.
For example, consider
...
...
@@ -640,7 +640,7 @@ But since autoloading happens on demand, if the top-level `User` by chance was
not yet loaded then Rails has no way to know whether
`Admin::User`
should load it
or raise
`NameError`
.
These kind of name conflicts are rare in practice
, but in case there's one
These kind of name conflicts are rare in practice
but, in case there's one,
`require_dependency`
provides a solution by making sure the constant needed to
trigger the heuristic is defined in the conflicting place.
...
...
@@ -955,8 +955,8 @@ require_dependency ‘square’
```
Only the leaves that are
**at least grandchildren**
have to be loaded that
way. Direct subclasses do not need to be preloaded
, and
if the hierarchy is
deeper intermediate classes will be autoloaded recursively from the bottom
way. Direct subclasses do not need to be preloaded
and,
if the hierarchy is
deeper
,
intermediate classes will be autoloaded recursively from the bottom
because their constant will appear in the class definitions as superclass.
### Autoloading and `require`
...
...
@@ -1059,7 +1059,7 @@ calls in an initializer to make sure certain constants are loaded upfront, for
example as an attempt to address the
[
gotcha with STIs
](
#autoloading-and-sti
)
.
Problem is, in development mode
[
autoloaded constants are wiped
](
#constant-reloading
)
if there is any relevant change in the file system. If that happens the
if there is any relevant change in the file system. If that happens the
n
we are in the very same situation the initializer wanted to avoid!
Calls to
`require_dependency`
have to be strategically written in autoloaded
...
...
@@ -1124,7 +1124,7 @@ end
That class definition now is robust.
It is interesting to note here that fix works because
`Hotel`
is a module, and
It is interesting to note here that
the
fix works because
`Hotel`
is a module, and
`Hotel::Image`
won’t look for
`Image`
in
`Object`
as it would if
`Hotel`
was a
class with
`Object`
in its ancestors. If
`Hotel`
was a class we would resort to
loading
`Hotel::Image`
with
`require_dependency`
. Furthermore, with that
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录