A module to automatically translate snake_case method calls into CamelCase method calls. For example:
class MyObject
include Snakeable
def FooBar
"baz"
end
end
MyObject.new.FooBar # => "baz"
MyObject.new.foo_bar # => "baz"
snake_case is the convention for Ruby. But sometimes a Ruby object is mirroring another system (database columns, API wrapper, etc) that is using camel case. This module allows you to use the ruby convention and have that automatically translated into the mirrored method.
Obviously the usual caviots with magic metaprogramming apply here:
- If implementing high performance code use the original CamelCase method. Each time you use the snake_case method it has to do a few additionl operations to verify the method should exist and translate into the CamelCase method.
- If you have other methods in your class that conflict with the magic snake case methods your methods should override the magic methods. But it could get confusing if your methods are inherited as well or are generated from their own magic metaprogramming.