Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
eddb9baf
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,发现更多精彩内容 >>
提交
eddb9baf
编写于
9月 20, 2017
作者:
S
Sean Griffin
提交者:
GitHub
9月 20, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #30624 from bogdanvlviv/deprecate_Module_reachable
Deprecate `Module#reachable?` method
上级
e7f39af3
27506535
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
23 addition
and
52 deletion
+23
-52
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+4
-0
activesupport/lib/active_support/core_ext/class/subclasses.rb
...vesupport/lib/active_support/core_ext/class/subclasses.rb
+0
-3
activesupport/lib/active_support/core_ext/module/reachable.rb
...vesupport/lib/active_support/core_ext/module/reachable.rb
+1
-0
activesupport/test/core_ext/module/reachable_test.rb
activesupport/test/core_ext/module/reachable_test.rb
+18
-10
guides/source/active_support_core_extensions.md
guides/source/active_support_core_extensions.md
+0
-39
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
eddb9baf
*
Deprecate
`Module#reachable?`
method.
*bogdanvlviv*
*
Add
`config/credentials.yml.enc`
to store production app secrets.
Allows saving any authentication credentials for third party services
...
...
activesupport/lib/active_support/core_ext/class/subclasses.rb
浏览文件 @
eddb9baf
# frozen_string_literal: true
require_relative
"../module/anonymous"
require_relative
"../module/reachable"
class
Class
begin
# Test if this Ruby supports each_object against singleton_class
...
...
activesupport/lib/active_support/core_ext/module/reachable.rb
浏览文件 @
eddb9baf
...
...
@@ -7,4 +7,5 @@ class Module
def
reachable?
#:nodoc:
!
anonymous?
&&
name
.
safe_constantize
.
equal?
(
self
)
end
deprecate
:reachable?
end
activesupport/test/core_ext/module/reachable_test.rb
浏览文件 @
eddb9baf
...
...
@@ -5,13 +5,17 @@
class
AnonymousTest
<
ActiveSupport
::
TestCase
test
"an anonymous class or module is not reachable"
do
assert
!
Module
.
new
.
reachable?
assert
!
Class
.
new
.
reachable?
assert_deprecated
do
assert
!
Module
.
new
.
reachable?
assert
!
Class
.
new
.
reachable?
end
end
test
"ordinary named classes or modules are reachable"
do
assert
Kernel
.
reachable?
assert
Object
.
reachable?
assert_deprecated
do
assert
Kernel
.
reachable?
assert
Object
.
reachable?
end
end
test
"a named class or module whose constant has gone is not reachable"
do
...
...
@@ -21,8 +25,10 @@ class AnonymousTest < ActiveSupport::TestCase
self
.
class
.
send
(
:remove_const
,
:C
)
self
.
class
.
send
(
:remove_const
,
:M
)
assert
!
c
.
reachable?
assert
!
m
.
reachable?
assert_deprecated
do
assert
!
c
.
reachable?
assert
!
m
.
reachable?
end
end
test
"a named class or module whose constants store different objects are not reachable"
do
...
...
@@ -35,9 +41,11 @@ class AnonymousTest < ActiveSupport::TestCase
eval
"class C; end"
eval
"module M; end"
assert
C
.
reachable?
assert
M
.
reachable?
assert
!
c
.
reachable?
assert
!
m
.
reachable?
assert_deprecated
do
assert
C
.
reachable?
assert
M
.
reachable?
assert
!
c
.
reachable?
assert
!
m
.
reachable?
end
end
end
guides/source/active_support_core_extensions.md
浏览文件 @
eddb9baf
...
...
@@ -674,44 +674,6 @@ M.parents # => [X::Y, X, Object]
NOTE: Defined in
`active_support/core_ext/module/introspection.rb`
.
### Reachable
A named module is reachable if it is stored in its corresponding constant. It means you can reach the module object via the constant.
That is what ordinarily happens, if a module is called "M", the
`M`
constant exists and holds it:
```
ruby
module
M
end
M
.
reachable?
# => true
```
But since constants and modules are indeed kind of decoupled, module objects can become unreachable:
```
ruby
module
M
end
orphan
=
Object
.
send
(
:remove_const
,
:M
)
# The module object is orphan now but it still has a name.
orphan
.
name
# => "M"
# You cannot reach it via the constant M because it does not even exist.
orphan
.
reachable?
# => false
# Let's define a module called "M" again.
module
M
end
# The constant M exists now again, and it stores a module
# object called "M", but it is a new instance.
orphan
.
reachable?
# => false
```
NOTE: Defined in
`active_support/core_ext/module/reachable.rb`
.
### Anonymous
A module may or may not have a name:
...
...
@@ -745,7 +707,6 @@ end
m
=
Object
.
send
(
:remove_const
,
:M
)
m
.
reachable?
# => false
m
.
anonymous?
# => false
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录