String Mix-in to convert CamelCase and snake_case
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
spec
.gitignore
.rspec
.travis.yml
CHANGELOG.md
Gemfile
LICENSE.txt
README.md
Rakefile
camel_snake.gemspec

README.md

camel_snake

Gem Version Build Status

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

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

The gem is available as open source under the terms of the MIT License.

Copyright (c) 2016 YASUTAKE Kiyoshi