SnakeCamel
This Gem provides several ways for conversation between CamalCase and snake_case.
Installation
Add this line to your application's Gemfile:
gem 'snake_camel'
And then execute:
$ bundle
Or install it yourself as:
$ gem install snake_camel
Methods
-
snakecase
-
snakecase!
-
camelcase
-
camelcase!
-
constant_name ('hello/world_sup' #=> Hello::WorldSup)
-
path_name ('Hello::WorldSup #=> hello/world_sup')
Usage
You have several ways to use it, it's pretty simple. Choose one, based on your need!
- If you don't care about what's under the hood:
require 'snake_camel'
'SnakeCamel'.snakecase #=> 'snake_camel'
or
'snake_camel'.camelcase #=> 'SnakeCamel'
- If you don't want to monkey-patch your String class:
require 'snake_camel/instance_methods'
foo = 'FooBar'
foo.extend SnakeCamel::InstanceMethods
foo.snakecase #=> 'foo_bar'
or
foo = 'foo_bar'
foo.extend SnakeCamel::InstanceMethods
foo.camelcase #=> 'FooBar'
- And you can use it like a regular method:
require 'snake_camel/methods'
SnakeCamel::Methods.snakecase('FooBar') #=> 'foo_bar'
SnakeCamel::Methods.camelcase('foo_bar') #=> 'FooBar'
Creator's notes
I know there are other gems that provide the same functionality as SnakeCamel, but I want to create something more gentle, more simple.
Contributing
- Fork it ( https://github.com/[my-github-username]/snake_camel/fork )
- 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 a new Pull Request
License
The gem is available as open source under the terms of the MIT License.