grab 0.0.1 → 0.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. data/README.md +13 -11
  2. data/lib/grab.rb +10 -4
  3. data/lib/grab/version.rb +1 -1
  4. metadata +1 -1
data/README.md CHANGED
@@ -2,20 +2,22 @@
2
2
 
3
3
  Grab provides an clean way to fetch multiple values from a hash. Instead of:
4
4
 
5
- ```
6
- def my_method(opts)
7
- foo = opts.fetch(:foo)
8
- bar = opts.fetch(:bar)
9
- end
10
- ```
5
+ def initialize(params)
6
+ foo = params.fetch(:foo)
7
+ bar = params.fetch(:bar)
8
+ end
11
9
 
12
10
  you can write:
13
11
 
14
- ```
15
- def my_method(opts)
16
- foo, bar = opts.grab(:foo, :bar)
17
- end
18
- ```
12
+ def initialize(params)
13
+ foo, bar = params.grab(:foo, :bar)
14
+ end
15
+
16
+ or if some of your params are optional:
17
+
18
+ def initialize(params)
19
+ foo, bar = params.values(:foo, :bar)
20
+ end
19
21
 
20
22
  ## Installation
21
23
 
@@ -1,11 +1,17 @@
1
1
  require "grab/version"
2
2
 
3
- module Grab
3
+ class Hash
4
+ alias_method :old_values, :values
5
+
4
6
  def grab(*keys)
5
7
  keys.map { |k| self.fetch(k) }
6
8
  end
7
- end
8
9
 
9
- class Hash
10
- include Grab
10
+ def values(*args)
11
+ if args.empty?
12
+ old_values
13
+ else
14
+ args.map { |k| self[k] }
15
+ end
16
+ end
11
17
  end
@@ -1,3 +1,3 @@
1
1
  module Grab
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: