just_maybe 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +13 -6
  3. data/lib/just_maybe/version.rb +1 -1
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72ef2ce85b41d39244227cb4c844a34a32e4eb12
4
- data.tar.gz: 9e82969ab7e6fd4f117f686cf9605d0eb745282b
3
+ metadata.gz: 197a32d73ce562bdb84b5407ab9103c3feaafe1d
4
+ data.tar.gz: c2e49cd9197f0da89a019ef356039f7ab15f08b4
5
5
  SHA512:
6
- metadata.gz: 369988e0deb62bad303c334d60ffa9624882498d23dabfd91b351ab511097a1338f64c1dac8418b05546385fd795daf6c62e8194f713ab5242a00026bc06a40e
7
- data.tar.gz: df965b85481a20aa6a68c3e1b7a529e7ec7b9b1aefc45549bd2f565b07ef2ed925d9f507e041759df1d1c19889d410de70f611a1ec299ac3323bd8c3d8a1f081
6
+ metadata.gz: dd72c9967ee2e05138a426444d5d988c8ebf8351372a5be7ce1536bf15934f2950611ab32cd20bacd4443d5caf4c73722173999765bcbfb15433b7c9b1348832
7
+ data.tar.gz: 29ad284e103668974a657d527295dce2be6483875e612b683c26b8a72a3c3e9a25cac7872fab45d5828262c82b62c13b5cda1ec90e6042d5f88ace12537f42c9
data/README.md CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
  An implementation of the "Maybe" pattern.
4
4
 
5
- The philosophy of this particular implementation of the Maybe pattern is that you should use the `Maybe` function to wrap values before returning them from any method that could potentially return `nil`. This forces the consumer of the returned object to pro-actively acknowledge that it could be `nil` by forcing them to use the `try` method to access it.
5
+ The philosophy behind this implementation of `Maybe` is to wrap optional values at the point of first contact.
6
6
 
7
- This implementation also does no monkey patching and does not rely on method missing or any other Ruby magic for it's implementation.
7
+ So for example, instead of allowing `Person.find` to return `nil` you return a `Maybe` wrapping either a `Person` or `nil`. This forces consumers of `Person.find` to access the underlying value with `try`, thus explicitly acknowledging the returned values could be a `Person` or `Nothing`.
8
8
 
9
- It also has a tiny API. Maybe objects respond to `nothing?`, `something?`, and `try`.
9
+ The implementation is extremely simple, does no monkey patching and does not rely on method missing.
10
+
11
+ It has a tiny API, providing three methods `nothing?`, `something?` and `try`.
10
12
 
11
13
 
12
14
  ## Installation
@@ -47,10 +49,10 @@ Maybe('anything')
47
49
  # => <Just:0x000000020e04f0 @object="anything">
48
50
 
49
51
  # Calling Maybe(nil) returns an instance of Nothing
50
- Maybe(nothing)
52
+ Maybe(nil)
51
53
  # => <Nothing:0x000000020b1718>
52
54
 
53
- # Instances of Just and Nothing respond to the replicate methods nothing? and something?
55
+ # Instances of Just and Nothing respond to the predicate methods nothing? and something?
54
56
  Maybe(42).nothing? # => false
55
57
  Maybe(42).something? # => true
56
58
  Maybe(nil).nothing? # => true
@@ -62,12 +64,17 @@ Maybe(40).try{|m| m.succ.succ } # => 42
62
64
 
63
65
  # When try is called on instances of Nothing it returns nil
64
66
  Maybe(nil).try{|m| m.succ.succ } # => nil
67
+
68
+ # A common pattern would be to use try || default
69
+ Maybe(41).try{|m| m.succ } || 0 # 42
70
+ Maybe(nil).try{|m| m.succ } || 0 # 0
65
71
  ```
66
72
 
67
73
 
74
+
68
75
  ## Notice
69
76
 
70
- The public interace of this gem was radically changed with the jump to version 1.0. If you were using version `0.2` or earlier you should pin the version in your Gemfile at "~> 0.2"
77
+ The public interface of this gem was radically changed with the jump to version 1.0. If you were using version `0.2` or earlier you should pin the version in your Gemfile at "~> 0.2"
71
78
 
72
79
  ## Related
73
80
  * [Null Objects and Falsiness](http://devblog.avdi.org/2011/05/30/null-objects-and-falsiness/)
@@ -1,3 +1,3 @@
1
1
  module JustMaybe
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: just_maybe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Greenly