From 0a6b54acd63f0f396eda6e1e5e2366ce91a35d79 Mon Sep 17 00:00:00 2001 From: take_cheeze Date: Fri, 20 Jun 2014 21:49:41 +0900 Subject: Reduce new string creation in `capitalize`, `downcase`, `upcase` method of `Symbol` class extension. Add test to check unmodified result is working. --- mrbgems/mruby-symbol-ext/mrblib/symbol.rb | 6 +++--- mrbgems/mruby-symbol-ext/test/symbol.rb | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb index 4cf18f647..b2615a760 100644 --- a/mrbgems/mruby-symbol-ext/mrblib/symbol.rb +++ b/mrbgems/mruby-symbol-ext/mrblib/symbol.rb @@ -25,7 +25,7 @@ class Symbol # Same as sym.to_s.capitalize.intern. def capitalize - self.to_s.capitalize.intern + (self.to_s.capitalize! || self).to_sym end ## @@ -35,7 +35,7 @@ class Symbol # Same as sym.to_s.downcase.intern. def downcase - self.to_s.downcase.intern + (self.to_s.downcase! || self).to_sym end ## @@ -45,7 +45,7 @@ class Symbol # Same as sym.to_s.upcase.intern. def upcase - self.to_s.upcase.intern + (self.to_s.upcase! || self).to_sym end ## diff --git a/mrbgems/mruby-symbol-ext/test/symbol.rb b/mrbgems/mruby-symbol-ext/test/symbol.rb index 59df7ea9d..c2695f1f8 100644 --- a/mrbgems/mruby-symbol-ext/test/symbol.rb +++ b/mrbgems/mruby-symbol-ext/test/symbol.rb @@ -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 -- cgit v1.2.3