Improve API around {Hash,Array}#replace
Ruby
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
example
lib
test
.gitignore
.travis.yml
.yardopts
BSD-LICENSE
Gemfile
README.md
Rakefile
replace_replace.gemspec

README.md

replace_replace

Build Status Gem Version

Description

Improve API around {Hash,Array}#replace. See my gist.

get
====
        |Array  |Hash
-----------------------
strict  |fetch  |fetch
auto    |[], at |[]


set
====
        |Array  |Hash
-----------------------
strict  |?       |?             => Provide this.
auto    |[]=     |[]=, store

Features

  • Strict replacement methods into Hash, Array
  • Pure Ruby :)

Usage

Overview

require 'replace_replace/core_ext'

[1, 2, 3].replace [4, 5, 6]          #=> [4, 5, 6]
[1, 2, 3].replace 1, 7               #=> [1, 7, 3]
[1, 2, 3].replace 3, 8               #=> IndexError


({a: 1, b: 2}.replace({c: 3, d: 4})) #=> {:c=>3, :d=>4}
({a: 1, b: 2}.replace(:a, 5))        #=> {:a=>5, :b=>2}
({a: 1, b: 2}.replace(:c, 7))        #=> KeyError

Requirements

Install

$ gem install replace_replace

Link

License

The 2-clause BSD License
Copyright (c) 2012 Kenichi Kamiya
See BSD-LICENSE for further details.