maybe.rb 1.0.0 → 1.1.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b0161b9efdecf4cc33db1c2e09e5485b026ce291
4
- data.tar.gz: f38f123c09332b4b3f180e0d654e25a36071b048
3
+ metadata.gz: 76f25a1f8164ed416c85278d29854b79f9cc1b82
4
+ data.tar.gz: 72c7c898320b68f6cbfcaed4fce6c6075303dc90
5
5
  SHA512:
6
- metadata.gz: b49abd1dd5b67ba7974e1d8896e86afed9fa7c5d228169322cc414bedf074396be964173bd6797ee4909ee6f4549b7b9078c25adf0d0af855ecc68abb2020a7d
7
- data.tar.gz: 272a780ec77be12dfb3e228de4215312a26ef2ff0cc847de9e016eff55d7ee9e2baa026ac7d6ed7c286799abc5f9d82df1fb158d77ae306e86be1e03ec0539dd
6
+ metadata.gz: 45a77cd9f4ea97a2f64e054984cfc18b20a277328c37e2f30911b6fb659d16b14c1149da74df1cb28803aad4f1fd27e9b146e5f3f5624f26682888ae10d5f3cf
7
+ data.tar.gz: 92166879a1c7df591a153b34512506d982b62f1b0d728bdddc0ddec2337de797ad10c0a80ee5a52810419c2fd76dc021ee3183dae7abc1a7fbba5c8b8ba47dc7
data/README.md CHANGED
@@ -57,6 +57,18 @@ This is disabled by default and the `Maybe` class itself doesn't rely on it and
57
57
  because it's not too pleasant for a library to implicitly patch built-in Ruby
58
58
  classes.
59
59
 
60
+ ## Installation
61
+
62
+ Because both "maybe" and "ruby-maybe" were already taken this Gem is
63
+ conveniently called "maybe.rb" on RubyGems, this means you'll need to install it
64
+ as following:
65
+
66
+ gem install maybe.rb
67
+
68
+ Or if you're using Bundler:
69
+
70
+ gem 'maybe.rb'
71
+
60
72
  ## Usage
61
73
 
62
74
  Load the Gem:
@@ -96,6 +96,16 @@ class Maybe
96
96
  #
97
97
  # maybe[0]['foo'].or(20)
98
98
  #
99
+ # If both arguments and a block are given the supplied block is called with
100
+ # the value returned by the `#[]` method of the wrapped object. For example:
101
+ #
102
+ # maybe = Maybe.new(:number => '10')
103
+ #
104
+ # maybe.maybe(:number) { |number| number.to_i } # => 10
105
+ #
106
+ # The block in this case is _only_ called when the `#[]` method returns a non
107
+ # nil value.
108
+ #
99
109
  # @param [Array] args
100
110
  #
101
111
  # @yieldparam [Mixed] wrapped The wrapped value
@@ -105,6 +115,10 @@ class Maybe
105
115
  def maybe(*args)
106
116
  if !args.empty?
107
117
  value = brackets? ? @wrapped[*args] : nil
118
+
119
+ if block_given? and value
120
+ value = yield value
121
+ end
108
122
  elsif @wrapped
109
123
  value = yield @wrapped
110
124
  end
@@ -1,7 +1,7 @@
1
1
  class Object
2
2
  ##
3
- # Wraps the current object in a Maybe instance, optionally calling {Maybe#get}
4
- # if an argument or block is given.
3
+ # Wraps the current object in a Maybe instance, optionally calling
4
+ # {Maybe#maybe} if an argument or block is given.
5
5
  #
6
6
  # @example
7
7
  # [10, 20, 30].maybe(0).or(50) # => 10
@@ -1,3 +1,3 @@
1
1
  class Maybe
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end # Maybe
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maybe.rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Olery B.V.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-31 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yard