Reputation: 2900
I've got string 'client.status'
which I want to convert to snakecase - client_status
. Is there a quick way to do so?
I tried:
> 'client.status'.underscore
"client.status"
> 'client.status'.parameterize
"client-status"
> 'client.status'.parameterize('_')
Traceback (most recent call last):
1: from (irb):81
ArgumentError (wrong number of arguments (given 1, expected 0))
Upvotes: 0
Views: 671
Reputation: 132
When passing the separator, you need to provide it as the keyword argument.
'client.status'.parameterize(separator: '_')
For more information, the source of the code is:
# File activesupport/lib/active_support/core_ext/string/inflections.rb, line 190
def parameterize(separator: "-", preserve_case: false)
ActiveSupport::Inflector.parameterize(self, separator: separator, preserve_case: preserve_case)
end
Upvotes: 3