Fix Ruby 2.7 compatibility in GenericService.underscore

pull/20417/head
Jean Boussier 5 years ago
parent 54749bf49c
commit d6bebcd248
  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