Deep duplicate Ruby objects.
Ruby Shell
Permalink
Failed to load latest commit information.
bin
lib
spec
.gitignore
.rspec
.travis.yml
.yardopts
Gemfile
LICENSE.txt
README.md
Rakefile
deep_dup.gemspec

README.md

DeepDup Build Status Code Climate Gem Version

Deep duplicate Ruby objects. Some objects cannot be dupped like nil, false, true, numbers, symbols and method objects. In those cases return themselves.

Usage

No monkey patching:

dupped = DeepDup.deep_dup('chunky')
dupped = DeepDup.deep_dup(['chunky', [:bacon, { hi: 5 }]])
dupped = DeepDup.deep_dup(['a', :a, 1, { bacon: { chunky: 'yeah' } }])
dupped = DeepDup.deep_dup(SomeClass.new)

array = [1, 2]
array << array
dupped = DeepDup.deep_dup(array)

With monkey patching

require 'deep_dup/core_ext/object'

dupped = 'chunky'.deep_dup
dupped = ['chunky', [:bacon, { hi: 5 }]].deep_dup
dupped = ['a', :a, 1, { bacon: { chunky: 'yeah' } }].deep_dup
dupped = SomeClass.new.deep_dup

array = [1, 2]
array << array
dupped = array.deep_dup

Installation

Add this line to your application's Gemfile:

gem 'deep_dup'

And then execute:

$ bundle

Or install it yourself as:

$ gem install deep_dup

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake rspec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ollie/deep_dup.

License

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

Credits

Thanks Ice Nine and Rails for inspiration.