No commit activity in last 3 years
No release in over 3 years
A small library that transforms UI strings into strings that can be used as method names.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
>= 0
>= 0

Runtime

 Project Readme

methodize_string

A small library that transforms UI strings into strings that can be used as method names.

It adds two methods to the String class:

String#methodize

String.methodize!

Basic usage:

require 'methodize_string'

'Save Changes'.methodize
=> "save_changes"

'Continue Reading...'.methodize
=> "continue_reading"

Accented character handling:

# By default, accented characters will be converted to non-accented characters.
"Ä Ö Ü".methodize
=> "a_o_u"

# But this behavior can be overridden.
"Ä Ö Ü".methodize(transliterate: false)
=> "ä_ö_ü"

Error handling:

# The non-bang method won't raise an error. It will just return nil if the string
# can't be converted.
''.methodize
=> nil

# The bang method raises an ArgumentError in cases where the string can't be converted.
''.methodize!
ArgumentError: Unable to convert string to a method string: ''

Limitations

  • English only.
  • Limited support for numbers in strings.
  • No support for things like currency codes, etc., at the moment.