camel_snake
This package provides a Mix-in module which extends String class and adds features to convert itself into CamelCase or snake_case.
Usage
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"
Installation
Add this line to your application's Gemfile:
gem 'camel_snake'
And then run bundle
command on your terminal.
Or install it yourself as:
$ gem install camel_snake
Motivation
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.
With refinements,
Ruby's recent feature, we can safely extend classes.
Jan Lelis's sugar_refinery uses this
feature. But it is not usable in older Ruby versions.
This module is simple and hopefully usable in many Ruby versions. And it meets my needs.
See Also
Contribution
- 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
License
The gem is available as open source under the terms of the MIT License.
Copyright (c) 2016 YASUTAKE Kiyoshi