Turn any object into a proxy delegating to another object. Like that:
require 'charlatan'
class ArrayProxy
include Charlatan.new(:array)
end
array_proxy = ArrayProxy.new([])
array_proxy << 'Hello'
array_proxy << 'World'
array_proxy.size # => 2
array_proxy.join(' ') # => 'Hello World'
# always wraps responses with the proxy class
other = array_proxy + ['Oh Hai']
other.class # => ArrayProxy
Planned features:
The idea is that a delegator object wrapping another object delegates method calls but it preserves the original type for return values which match the wrapped object's kind. This means if you decorate an array object and you call concat on the decorator you will get an instance of the decorator back rather than an array.
Other cool aspects of this library:
Add this line to your application's Gemfile:
gem 'charlatan'
And then execute:
$ bundle
Or install it yourself as:
$ gem install charlatan
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)