Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
39e4796b
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 搜索 >>
未验证
提交
39e4796b
编写于
5月 06, 2020
作者:
R
Ryuta Kamizono
提交者:
GitHub
5月 06, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #39155 from kamipo/symbol_starts_ends_with
Add 3rd person aliases of `Symbol#start_with?` and `Symbol#end_with?`
上级
70ddb8a7
62a20c2a
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
85 addition
and
13 deletion
+85
-13
activesupport/CHANGELOG.md
activesupport/CHANGELOG.md
+6
-2
activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
...rt/lib/active_support/core_ext/string/starts_ends_with.rb
+2
-4
activesupport/lib/active_support/core_ext/symbol.rb
activesupport/lib/active_support/core_ext/symbol.rb
+3
-0
activesupport/lib/active_support/core_ext/symbol/starts_ends_with.rb
...rt/lib/active_support/core_ext/symbol/starts_ends_with.rb
+14
-0
activesupport/test/core_ext/string_ext_test.rb
activesupport/test/core_ext/string_ext_test.rb
+7
-7
activesupport/test/core_ext/symbol_ext_test.rb
activesupport/test/core_ext/symbol_ext_test.rb
+28
-0
guides/source/active_support_core_extensions.md
guides/source/active_support_core_extensions.md
+25
-0
未找到文件。
activesupport/CHANGELOG.md
浏览文件 @
39e4796b
*
Deprecate
`starts_with?`
and
`ends_with?`
for String core extensions.
Use the native
`start_with?`
and
`end_with?`
instead.
*
Add 3rd person aliases of
`Symbol#start_with?`
and
`Symbol#end_with?`
.
```ruby
:foo.starts_with?("f") # => true
:foo.ends_with?("o") # => true
```
*Ryuta Kamizono*
...
...
activesupport/lib/active_support/core_ext/string/starts_ends_with.rb
浏览文件 @
39e4796b
# frozen_string_literal: true
class
String
alias_method
:starts_with?
,
:start_with?
alias_method
:ends_with?
,
:end_with?
deprecate
starts_with?: :start_with?
deprecate
ends_with?: :end_with?
alias
:starts_with?
:start_with?
alias
:ends_with?
:end_with?
end
activesupport/lib/active_support/core_ext/symbol.rb
0 → 100644
浏览文件 @
39e4796b
# frozen_string_literal: true
require
"active_support/core_ext/symbol/starts_ends_with"
activesupport/lib/active_support/core_ext/symbol/starts_ends_with.rb
0 → 100644
浏览文件 @
39e4796b
# frozen_string_literal: true
class
Symbol
def
start_with?
(
prefix
)
to_s
.
start_with?
(
prefix
)
end
unless
:a
.
respond_to?
(
:start_with?
)
def
end_with?
(
suffix
)
to_s
.
end_with?
(
suffix
)
end
unless
:a
.
respond_to?
(
:end_with?
)
alias
:starts_with?
:start_with?
alias
:ends_with?
:end_with?
end
activesupport/test/core_ext/string_ext_test.rb
浏览文件 @
39e4796b
...
...
@@ -239,15 +239,15 @@ def test_ord
assert_equal
97
,
"abc"
.
ord
end
def
test_
deprecated_
starts_ends_with_alias
def
test_starts_ends_with_alias
s
=
"hello"
assert
_deprecated
{
assert
s
.
starts_with?
(
"h"
)
}
assert
_deprecated
{
assert
s
.
starts_with?
(
"hel"
)
}
assert_
deprecated
{
assert_not
s
.
starts_with?
(
"el"
)
}
assert
s
.
starts_with?
(
"h"
)
assert
s
.
starts_with?
(
"hel"
)
assert_
not
s
.
starts_with?
(
"el"
)
assert
_deprecated
{
assert
s
.
ends_with?
(
"o"
)
}
assert
_deprecated
{
assert
s
.
ends_with?
(
"lo"
)
}
assert_
deprecated
{
assert_not
s
.
ends_with?
(
"el"
)
}
assert
s
.
ends_with?
(
"o"
)
assert
s
.
ends_with?
(
"lo"
)
assert_
not
s
.
ends_with?
(
"el"
)
end
def
test_string_squish
...
...
activesupport/test/core_ext/symbol_ext_test.rb
0 → 100644
浏览文件 @
39e4796b
# frozen_string_literal: true
require_relative
"../abstract_unit"
require
"active_support/core_ext/symbol"
class
SymbolStartsEndsWithTest
<
ActiveSupport
::
TestCase
def
test_start_end_with
s
=
:hello
assert
s
.
start_with?
(
"h"
)
assert
s
.
start_with?
(
"hel"
)
assert_not
s
.
start_with?
(
"el"
)
assert
s
.
end_with?
(
"o"
)
assert
s
.
end_with?
(
"lo"
)
assert_not
s
.
end_with?
(
"el"
)
end
def
test_starts_ends_with_alias
s
=
:hello
assert
s
.
starts_with?
(
"h"
)
assert
s
.
starts_with?
(
"hel"
)
assert_not
s
.
starts_with?
(
"el"
)
assert
s
.
ends_with?
(
"o"
)
assert
s
.
ends_with?
(
"lo"
)
assert_not
s
.
ends_with?
(
"el"
)
end
end
guides/source/active_support_core_extensions.md
浏览文件 @
39e4796b
...
...
@@ -1212,6 +1212,17 @@ The `inquiry` method converts a string into a `StringInquirer` object making equ
NOTE: Defined in
`active_support/core_ext/string/inquiry.rb`
.
### `starts_with?` and `ends_with?`
Active Support defines 3rd person aliases of
`String#start_with?`
and
`String#end_with?`
:
```
ruby
"foo"
.
starts_with?
(
"f"
)
# => true
"foo"
.
ends_with?
(
"o"
)
# => true
```
NOTE: Defined in
`active_support/core_ext/string/starts_ends_with.rb`
.
### `strip_heredoc`
The method
`strip_heredoc`
strips indentation in heredocs.
...
...
@@ -1747,6 +1758,20 @@ INFO: The three of them return `nil` for blank receivers.
NOTE: Defined in
`active_support/core_ext/string/conversions.rb`
.
Extensions to `Symbol`
----------------------
### `starts_with?` and `ends_with?`
Active Support defines 3rd person aliases of
`Symbol#start_with?`
and
`Symbol#end_with?`
:
```
ruby
:foo
.
starts_with?
(
"f"
)
# => true
:foo
.
ends_with?
(
"o"
)
# => true
```
NOTE: Defined in
`active_support/core_ext/symbol/starts_ends_with.rb`
.
Extensions to `Numeric`
-----------------------
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录