Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/grpc/generic/service.rb

Overview

Extend String to add a method underscore

Instance Method Summary collapse

Instance Method Details

#underscoreObject

creates a new string that is the underscore separate version of this one.

E.g, PrintHTML -> print_html AMethod -> a_method AnRpc -> an_rpc



41
42
43
44
45
46
47
48
# File 'lib/grpc/generic/service.rb', line 41

def underscore
  word = dup
  word.gsub!(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
  word.gsub!(/([a-z\d])([A-Z])/, '\1_\2')
  word.tr!('-', '_')
  word.downcase!
  word
end