Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c699a4da
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,体验更适合开发者的 AI 搜索 >>
提交
c699a4da
编写于
5月 01, 2008
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ruby 1.9 compat: compatibility wrapper for new Module#const_defined? behavior
上级
1f2a4b37
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
13 deletion
+18
-13
activesupport/lib/active_support/dependencies.rb
activesupport/lib/active_support/dependencies.rb
+16
-5
activesupport/test/inflector_test.rb
activesupport/test/inflector_test.rb
+2
-8
未找到文件。
activesupport/lib/active_support/dependencies.rb
浏览文件 @
c699a4da
...
...
@@ -120,15 +120,26 @@ def qualified_const_defined?(path)
# We can't use defined? because it will invoke const_missing for the parent
# of the name we are checking.
names
.
inject
(
Object
)
do
|
mod
,
name
|
return
false
unless
mod
.
const_defined?
name
return
false
unless
uninherited_const_defined?
(
mod
,
name
)
mod
.
const_get
name
end
return
true
end
if
Module
.
method
(:
const_defined?
).
arity
==
1
# Does this module define this constant?
# Wrapper to accomodate changing Module#const_defined? in Ruby 1.9
def
uninherited_const_defined?
(
mod
,
const
)
mod
.
const_defined?
(
const
)
end
else
def
uninherited_const_defined?
(
mod
,
const
)
#:nodoc:
mod
.
const_defined?
(
const
,
false
)
end
end
# Given +path+, a filesystem path to a ruby file, return an array of constant
# paths which would cause Dependencies to attempt to load this file.
#
def
loadable_constants_for_path
(
path
,
bases
=
load_paths
)
path
=
$1
if
path
=~
/\A(.*)\.rb\Z/
expanded_path
=
File
.
expand_path
(
path
)
...
...
@@ -237,7 +248,7 @@ def load_missing_constant(from_mod, const_name)
raise
ArgumentError
,
"A copy of
#{
from_mod
}
has been removed from the module tree but is still active!"
end
raise
ArgumentError
,
"
#{
from_mod
}
is not missing constant
#{
const_name
}
!"
if
from_mod
.
const_defined?
(
const_name
)
raise
ArgumentError
,
"
#{
from_mod
}
is not missing constant
#{
const_name
}
!"
if
uninherited_const_defined?
(
from_mod
,
const_name
)
qualified_name
=
qualified_name_for
from_mod
,
const_name
path_suffix
=
qualified_name
.
underscore
...
...
@@ -246,12 +257,12 @@ def load_missing_constant(from_mod, const_name)
file_path
=
search_for_file
(
path_suffix
)
if
file_path
&&
!
loaded
.
include?
(
File
.
expand_path
(
file_path
))
# We found a matching file to load
require_or_load
file_path
raise
LoadError
,
"Expected
#{
file_path
}
to define
#{
qualified_name
}
"
unless
from_mod
.
const_defined?
(
const_name
)
raise
LoadError
,
"Expected
#{
file_path
}
to define
#{
qualified_name
}
"
unless
uninherited_const_defined?
(
from_mod
,
const_name
)
return
from_mod
.
const_get
(
const_name
)
elsif
mod
=
autoload_module!
(
from_mod
,
const_name
,
qualified_name
,
path_suffix
)
return
mod
elsif
(
parent
=
from_mod
.
parent
)
&&
parent
!=
from_mod
&&
!
from_mod
.
parents
.
any?
{
|
p
|
p
.
const_defined?
(
const_name
)
}
!
from_mod
.
parents
.
any?
{
|
p
|
uninherited_const_defined?
(
p
,
const_name
)
}
# If our parents do not have a constant named +const_name+ then we are free
# to attempt to load upwards. If they do have such a constant, then this
# const_missing must be due to from_mod::const_name, which should not
...
...
activesupport/test/inflector_test.rb
浏览文件 @
c699a4da
...
...
@@ -120,14 +120,8 @@ def test_constantize
assert_raises
(
NameError
)
{
Inflector
.
constantize
(
"InvalidClass
\n
"
)
}
end
if
RUBY_VERSION
<
'1.9.0'
def
test_constantize_does_lexical_lookup
assert_raises
(
NameError
)
{
Inflector
.
constantize
(
"Ace::Base::InflectorTest"
)
}
end
else
def
test_constantize_does_dynamic_lookup
assert_equal
self
.
class
,
Inflector
.
constantize
(
"Ace::Base::InflectorTest"
)
end
def
test_constantize_does_lexical_lookup
assert_raises
(
NameError
)
{
Inflector
.
constantize
(
"Ace::Base::InflectorTest"
)
}
end
def
test_ordinal
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录