Skip to content

Commit 817f978

Browse files
authored
Merge pull request #7 from frank-west-iii/issue-5-no-value-usage
Update README for HashDiff::NO_VALUE usage & bump
2 parents 0e43f6e + 3962452 commit 817f978

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# HashDiff
2+
23
[![Build Status](https://travis-ci.org/CodingZeal/hash_diff.png?branch=master)](https://travis-ci.org/CodingZeal/hash_diff) [![Code Climate](https://codeclimate.com/github/CodingZeal/hash_diff.png)](https://codeclimate.com/github/CodingZeal/hash_diff) [![Gem Version](https://badge.fury.io/rb/hash_diff.png)](http://badge.fury.io/rb/hash_diff)
34

45
Deep comparison of Ruby Hash objects
@@ -31,7 +32,8 @@ Easily find the differences between two Ruby hashes.
3132
one: 'foo1'
3233
}
3334
},
34-
num: 1
35+
num: 1,
36+
favorite_restaurant: "Shoney's"
3537
}
3638

3739
right = {
@@ -43,7 +45,8 @@ Easily find the differences between two Ruby hashes.
4345
two: 'foo2'
4446
}
4547
},
46-
word: 'monkey'
48+
word: 'monkey',
49+
favorite_restaurant: nil
4750
}
4851

4952
hash_diff = HashDiff::Comparison.new( left, right )
@@ -52,19 +55,23 @@ Easily find the differences between two Ruby hashes.
5255
Comparison#diff returns the left and right side differences
5356

5457
```ruby
55-
hash_diff.diff # => { foo: ["bar", "bar2"], bar: ["foo", "foo2"], nested: { foo: ["bar", "bar2"], bar: { one: ["foo1", nil], two: [nil, "foo2"] } }, num: [1, nil], word: [nil, "monkey"] }
58+
hash_diff.diff # => { foo: ["bar", "bar2"], bar: ["foo", "foo2"], nested: { foo: ["bar", "bar2"], bar: { one: ["foo1", HashDiff::NO_VALUE], two: [HashDiff::NO_VALUE, "foo2"] } }, num: [1, HashDiff::NO_VALUE], word: [HashDiff::NO_VALUE, "monkey"], favorite_restaurant: ["Shoney's", nil] }
5659
```
5760

61+
#### Missing keys
62+
63+
When there is a key that exists on one side it will return `HashDiff::NO_VALUE` to represent a missing key.
64+
5865
Comparison#left_diff returns only the left side differences
5966

6067
```ruby
61-
hash_diff.left_diff # => { foo: "bar2", bar: "foo2", nested: { foo: "bar2", bar: { one: nil, two: "foo2" } }, num: nil, word: "monkey" }
68+
hash_diff.left_diff # => {:foo=>"bar2", :bar=>"foo2", :nested=>{:foo=>"bar2", :bar=>{:one=>HashDiff::NO_VALUE, :two=>"foo2"}}, :num=>HashDiff::NO_VALUE, :favorite_restaurant=>nil, :word=>"monkey"}
6269
```
6370

6471
Comparison#right_diff returns only the right side differences
6572

6673
```ruby
67-
hash_diff.right_diff # => { foo: "bar", bar: "foo", nested: { foo: "bar", bar: { one: "foo1", two: nil } }, num: 1, word: nil }
74+
hash_diff.right_diff # => {:foo=>"bar", :bar=>"foo", :nested=>{:foo=>"bar", :bar=>{:one=>"foo1", :two=>HashDiff::NO_VALUE}}, :num=>1, :favorite_restaurant=>"Shoney's", :word=>HashDiff::NO_VALUE}
6875
```
6976

7077
You can also use these shorthand methods
@@ -91,7 +98,7 @@ Hash#diff is not provided by default, and monkey patching is frowned upon by som
9198

9299
Authored by the Engineering Team of [Coding ZEAL](https://codingzeal.com?utm_source=github)
93100

94-
Copyright (c) 2017 Zeal, LLC. Licensed under the [MIT license](https://opensource.org/licenses/MIT).
101+
Copyright (c) 2017 Zeal, LLC. Licensed under the [MIT license](https://opensource.org/licenses/MIT).
95102

96103
## Contributing
97104

lib/hash_diff/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module HashDiff
2-
VERSION = "0.8.0"
2+
VERSION = "1.0.0"
33
end

0 commit comments

Comments
 (0)