Converts the given string to a symbol-style string.
This is intended to be a kind of inverse of
#humanize, but a little more robust than dehumanize. This is a strong symbolizer, converting hyphens, non-standard characters, spaces, camelcase, etc. to underscored strings. The main inspiration for this came after finding that
#dehumanize did not support dehumanizing strings containing numbers, e.g.
"Abstract Object 1".dehumanize # => "abstract_object1" "Abstract Object 1".symbolizify # => "abstract_object_1"
symbolizify was chosen in order to avoid naming collisions or confusion with other
symbolize gems in the market, and to reinforce the idea that this doesn't actually convert a string to a symbol, but rather converts it to a symbol-style string.
Add this line to your application's Gemfile:
gem 'symbolizify', '>= 0.2.0'
And then execute:
Or install it yourself as:
$ gem install symbolizify
Call symbolizify on any string to turn it into a symbol-style string! Removes non-word/non-digit characters, reduces everything to lowercase with underscores separating words and numbers, e.g.
'Personal Phone '.symbolizify # => 'personal_phone', 'Home address'.symbolizify # => 'home_address', 'HatRack'.symbolizify # => 'hat_rack', 'Who is _why?'.symbolizify # => 'who_is_why', 'Person 1'.symbolizify # => 'person_1', 'Personel! #231'.symbolizify # => 'personel_231', 'Wang chung !'.symbolizify # => 'wang_chung', 'Shekibobo is great!'.symbolizify # => 'shekibobo_is_great', 'firstname.lastname@example.org'.symbolizify # => 'test_subject_example_com'
- Fork it
- Create your feature branch (
git checkout -b my-new-feature)
- Commit your changes (
git commit -am 'Add some feature')
- Push to the branch (
git push origin my-new-feature)
- Create new Pull Request