ruby-changes:46414
From: duerst <ko1@a...>
Date: Tue, 2 May 2017 14:34:30 +0900 (JST)
Subject: [ruby-changes:46414] duerst:r58538 (trunk): rework definition of String#unicode_normalize! and #unicode_normalized?
duerst 2017-05-02 14:34:25 +0900 (Tue, 02 May 2017) New Revision: 58538 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58538 Log: rework definition of String#unicode_normalize! and #unicode_normalized? simplify String#unicode_normalize! and #unicode_normalized? in lib/unicode_normalize.rb by redefining them in lib/unicode_normalize/normalize.rb Modified files: trunk/lib/unicode_normalize/normalize.rb trunk/lib/unicode_normalize.rb Index: lib/unicode_normalize.rb =================================================================== --- lib/unicode_normalize.rb (revision 58537) +++ lib/unicode_normalize.rb (revision 58538) @@ -42,8 +42,7 @@ class String https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize.rb#L42 # def unicode_normalize!(form = :nfc) require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize - # String.send(:define_method, :unicode_normalize!, ->(form = :nfc) { replace(unicode_normalize(form)) } ) - replace(unicode_normalize(form)) + unicode_normalize! form end # :call-seq: @@ -65,8 +64,7 @@ class String https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize.rb#L64 # def unicode_normalized?(form = :nfc) require 'unicode_normalize/normalize.rb' unless defined? UnicodeNormalize - # String.send(:define_method, :unicode_normalized?, ->(form = :nfc) { UnicodeNormalize.normalized?(self, form) } ) - UnicodeNormalize.normalized?(self, form) + unicode_normalized? form end end Index: lib/unicode_normalize/normalize.rb =================================================================== --- lib/unicode_normalize/normalize.rb (revision 58537) +++ lib/unicode_normalize/normalize.rb (revision 58538) @@ -157,11 +157,18 @@ module UnicodeNormalize # :nodoc: https://github.com/ruby/ruby/blob/trunk/lib/unicode_normalize/normalize.rb#L157 raise Encoding::CompatibilityError, "Unicode Normalization not appropriate for #{encoding}" end end - end # module class String # :nodoc: def unicode_normalize(form = :nfc) UnicodeNormalize.normalize(self, form) end + + def unicode_normalize!(form = :nfc) + replace(UnicodeNormalize.normalize(self, form)) + end + + def unicode_normalized?(form = :nfc) + UnicodeNormalize.normalized?(self, form) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/