This package provides a Mix-in module which extends String class and adds features to convert itself into CamelCase or snake_case.
require 'camel_snake' "FooBar".extend(CamelSnake).to_snake #=> "foo_bar" "bar_baz".extend(CamelSnake).to_camel #=> "BarBaz" # Or you can do bellow String.include CamelSnake "FooBar".to_snake #=> "foo_bar" "bar_baz".to_camel #=> "BarBaz"
Add this line to your application's Gemfile:
And then run
bundle command on your terminal.
Or install it yourself as:
$ gem install camel_snake
I know there are a lot of packages which provide similar features including
ActiveSupport in Rails.
But I want a minimul package which gives only these two conversion functions out of Rails.
This module is simple and hopefully usable in many Ruby versions. And it meets my needs.
- 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
The gem is available as open source under the terms of the MIT License.
Copyright (c) 2016 YASUTAKE Kiyoshi