Merge pull request #20417 from casperisfine/ruby-27-frozen-strings

Fix Ruby 2.7 compatibility in GenericService.underscore
pull/22959/head
apolcyn 5 years ago committed by GitHub
commit fed09cbe2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      src/ruby/lib/grpc/generic/service.rb
  2. 2
      src/ruby/spec/generic/service_spec.rb

@ -31,6 +31,7 @@ module GRPC
#
# @param s [String] the string to be converted.
def self.underscore(s)
s = +s # Avoid mutating the argument, as it might be frozen.
s.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
s.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
s.tr!('-', '_')

@ -55,6 +55,8 @@ describe GenericService do
expect(GenericService.underscore('AMethod')).to eq('a_method')
expect(GenericService.underscore('PrintHTML')).to eq('print_html')
expect(GenericService.underscore('SeeHTMLBooks')).to eq('see_html_books')
expect(GenericService.underscore('SeeHTMLBooks'.freeze)).to eq('see_html_books')
end
end

Loading…
Cancel
Save