Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
04df7bb0
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,发现更多精彩内容 >>
提交
04df7bb0
编写于
1月 12, 2012
作者:
X
Xavier Noria
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
deprecates Module#local_constant_names
上级
3c645488
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
27 addition
and
6 deletion
+27
-6
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+3
-0
activesupport/lib/active_support/core_ext/module/introspection.rb
...pport/lib/active_support/core_ext/module/introspection.rb
+12
-2
activesupport/lib/active_support/dependencies.rb
activesupport/lib/active_support/dependencies.rb
+2
-2
activesupport/test/core_ext/module_test.rb
activesupport/test/core_ext/module_test.rb
+6
-0
railties/guides/source/active_support_core_extensions.textile
...ties/guides/source/active_support_core_extensions.textile
+4
-2
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
04df7bb0
## Rails 4.0.0 (unreleased) ##
## Rails 4.0.0 (unreleased) ##
*
Deprecates the compatibility method Module#local_constant_names,
use Module#local_constants instead (which returns symbols).
*fxn*
*
Deletes the compatibility method Module#method_names,
*
Deletes the compatibility method Module#method_names,
use Module#methods from now on (which returns symbols).
*fxn*
use Module#methods from now on (which returns symbols).
*fxn*
...
...
activesupport/lib/active_support/core_ext/module/introspection.rb
浏览文件 @
04df7bb0
...
@@ -61,9 +61,19 @@ def local_constants #:nodoc:
...
@@ -61,9 +61,19 @@ def local_constants #:nodoc:
constants
(
false
)
constants
(
false
)
end
end
# Returns the names of the constants defined locally rather than the
# *DEPRECATED*: Use +local_constants+ instead.
# constants themselves. See <tt>local_constants</tt>.
#
# Returns the names of the constants defined locally as strings.
#
# module M
# X = 1
# end
# M.local_constant_names # => ["X"]
#
# This method is useful for forward compatibility, since Ruby 1.8 returns
# constant names as strings, whereas 1.9 returns them as symbols.
def
local_constant_names
def
local_constant_names
ActiveSupport
::
Deprecation
.
warn
(
'Module#local_constant_names is deprecated, use Module#local_constants instead'
,
caller
)
local_constants
.
map
{
|
c
|
c
.
to_s
}
local_constants
.
map
{
|
c
|
c
.
to_s
}
end
end
end
end
activesupport/lib/active_support/dependencies.rb
浏览文件 @
04df7bb0
...
@@ -105,7 +105,7 @@ def new_constants
...
@@ -105,7 +105,7 @@ def new_constants
next
unless
mod
.
is_a?
(
Module
)
next
unless
mod
.
is_a?
(
Module
)
# Get a list of the constants that were added
# Get a list of the constants that were added
new_constants
=
mod
.
local_constant
_name
s
-
original_constants
new_constants
=
mod
.
local_constants
-
original_constants
# self[namespace] returns an Array of the constants that are being evaluated
# self[namespace] returns an Array of the constants that are being evaluated
# for that namespace. For instance, if parent.rb requires child.rb, the first
# for that namespace. For instance, if parent.rb requires child.rb, the first
...
@@ -133,7 +133,7 @@ def watch_namespaces(namespaces)
...
@@ -133,7 +133,7 @@ def watch_namespaces(namespaces)
namespaces
.
map
do
|
namespace
|
namespaces
.
map
do
|
namespace
|
module_name
=
Dependencies
.
to_constant_name
(
namespace
)
module_name
=
Dependencies
.
to_constant_name
(
namespace
)
original_constants
=
Dependencies
.
qualified_const_defined?
(
module_name
)
?
original_constants
=
Dependencies
.
qualified_const_defined?
(
module_name
)
?
Inflector
.
constantize
(
module_name
).
local_constant
_name
s
:
[]
Inflector
.
constantize
(
module_name
).
local_constants
:
[]
watching
<<
module_name
watching
<<
module_name
@stack
[
module_name
]
<<
original_constants
@stack
[
module_name
]
<<
original_constants
...
...
activesupport/test/core_ext/module_test.rb
浏览文件 @
04df7bb0
...
@@ -212,6 +212,12 @@ def test_parents
...
@@ -212,6 +212,12 @@ def test_parents
def
test_local_constants
def
test_local_constants
assert_equal
%w(Constant1 Constant3)
,
Ab
.
local_constants
.
sort
.
map
(
&
:to_s
)
assert_equal
%w(Constant1 Constant3)
,
Ab
.
local_constants
.
sort
.
map
(
&
:to_s
)
end
end
def
test_local_constant_names
ActiveSupport
::
Deprecation
.
silence
do
assert_equal
%w(Constant1 Constant3)
,
Ab
.
local_constant_names
end
end
end
end
module
BarMethodAliaser
module
BarMethodAliaser
...
...
railties/guides/source/active_support_core_extensions.textile
浏览文件 @
04df7bb0
...
@@ -692,7 +692,8 @@ NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
...
@@ -692,7 +692,8 @@ NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
h4. Constants
h4. Constants
The method +local_constants+ returns the names of the constants that have been defined in the receiver module:
The method +local_constants+ returns the names of the constants that have been
defined in the receiver module:
<ruby>
<ruby>
module X
module X
...
@@ -708,7 +709,8 @@ X.local_constants # => [:X1, :X2, :Y]
...
@@ -708,7 +709,8 @@ X.local_constants # => [:X1, :X2, :Y]
X::Y.local_constants # => [:Y1, :X1]
X::Y.local_constants # => [:Y1, :X1]
</ruby>
</ruby>
The names are returned as symbols. The method +local_constant_names+ always returns strings.
The names are returned as symbols. (The method +local_constant_names+ returns
strings, but +local_constant_names+ is deprecated.)
NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
NOTE: Defined in +active_support/core_ext/module/introspection.rb+.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录