The ruby core itself has no support to convert a string from (upper) camel case to (also known as pascal case) to underscore (also known as snake case).
So you need either to make your own implementation or use an existing gem.
There is a small ruby gem called lucky_case which allows you to convert a string from any of the 10+ supported cases to another case easily:
require 'lucky_case'
# convert to snake case string
LuckyCase.snake_case('CamelCaseString') # => 'camel_case_string'
# or the opposite way
LuckyCase.pascal_case('camel_case_string') # => 'CamelCaseString'
You can even monkey patch the String class if you want to:
require 'lucky_case/string'
'CamelCaseString'.snake_case # => 'camel_case_string'
'CamelCaseString'.snake_case! # => 'camel_case_string' and overwriting original
Have a look at the offical repository for more examples and documentation: