mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Reduce new string creation in capitalize, downcase, upcase method of Symbol class extension.
Add test to check unmodified result is working.
This commit is contained in:
committed by
Yukihiro "Matz" Matsumoto
parent
c938b2f656
commit
0a6b54acd6
@@ -25,7 +25,7 @@ class Symbol
|
||||
# Same as <code>sym.to_s.capitalize.intern</code>.
|
||||
|
||||
def capitalize
|
||||
self.to_s.capitalize.intern
|
||||
(self.to_s.capitalize! || self).to_sym
|
||||
end
|
||||
|
||||
##
|
||||
@@ -35,7 +35,7 @@ class Symbol
|
||||
# Same as <code>sym.to_s.downcase.intern</code>.
|
||||
|
||||
def downcase
|
||||
self.to_s.downcase.intern
|
||||
(self.to_s.downcase! || self).to_sym
|
||||
end
|
||||
|
||||
##
|
||||
@@ -45,7 +45,7 @@ class Symbol
|
||||
# Same as <code>sym.to_s.upcase.intern</code>.
|
||||
|
||||
def upcase
|
||||
self.to_s.upcase.intern
|
||||
(self.to_s.upcase! || self).to_sym
|
||||
end
|
||||
|
||||
##
|
||||
|
||||
@@ -19,14 +19,17 @@ end
|
||||
assert("Symbol#capitalize") do
|
||||
assert_equal :Hello, :hello.capitalize
|
||||
assert_equal :Hello, :HELLO.capitalize
|
||||
assert_equal :Hello, :Hello.capitalize
|
||||
end
|
||||
|
||||
assert("Symbol#downcase") do
|
||||
assert_equal :hello, :hEllO.downcase
|
||||
assert_equal :hello, :hello.downcase
|
||||
end
|
||||
|
||||
assert("Symbol#upcase") do
|
||||
assert_equal :HELLO, :hEllO.upcase
|
||||
assert_equal :HELLO, :HELLO.upcase
|
||||
end
|
||||
|
||||
assert("Symbol#casecmp") do
|
||||
|
||||
Reference in New Issue
Block a user