method_matchable 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e690c77259f7bbf2cb638e7455015b3dbc226be92dce4975bcc2025a39c079d
4
- data.tar.gz: 6c8810420757f48e8c7e67db53358f8a32230a8acd829228a3750394e9f3caef
3
+ metadata.gz: 3947cb25e3939810fbea082dd65c60b6e970a46a06eacf601bc35aff93212639
4
+ data.tar.gz: 3d5de65719547b57360988be18ed21b4fee2b5d8841648c6688ba8704dd7b543
5
5
  SHA512:
6
- metadata.gz: e293a6c21ca0417acd78fc2a7023b2f9c08e8bbdd24af0b9566e21413b6352d959673c009534c810b9408c6f1c0efd06dfbca94b38c1dcb974ea88319f5b1cc1
7
- data.tar.gz: 4cc9b6311a35f92f2750cd269bce191404d5978eb4f87ed599bf272fbdad6e13593db2d86ab4d64b38e24108f53a8b856cec32f902b56506510c55043b7a7075
6
+ metadata.gz: 7337a741ca40073dbfcc3b08ffa4949205dfee9f22de2e87913c5b85415b3137e810c95fdf24db5a84b7cab9ae7430078554a33727d8ff5c241b77c2be8074b7
7
+ data.tar.gz: f25f58a376062315bb9d4beff786371974449bd729f2597df2b043d63fdf4759651ffd037790b5ed478afc926615b38e1625b2a2553f35458850a4c2973c4e50
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # MethodMatchable
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/kokuyouwind/method_matchable.svg?style=svg)](https://circleci.com/gh/kokuyouwind/method_matchable)
4
+ [![Gem Version](https://badge.fury.io/rb/method_matchable.svg)](https://badge.fury.io/rb/method_matchable)
5
+
3
6
  Match with methods in hash patterns!
4
7
 
5
8
  ## Installation
@@ -23,7 +26,7 @@ Or install it yourself as:
23
26
 
24
27
  ```ruby
25
28
  Person = Struct.new(:first_name, :last_name) do
26
- include MethodMatchable
29
+ include MethodMatchable::Base
27
30
 
28
31
  def full_name
29
32
  "#{first_name} #{last_name}"
@@ -34,6 +37,17 @@ case Person.new('Hotaru', 'Shiragiku')
34
37
  in { full_name: name }
35
38
  p name # => 'Hotaru Shiragiku'
36
39
  end
40
+
41
+ # You can use both original keys and method keys
42
+ class Hash
43
+ prepend MethodMatchable::Base
44
+ end
45
+
46
+ case { key: :value}
47
+ in { key: v, size: size}
48
+ p v # => :value
49
+ p size # => 1
50
+ end
37
51
  ```
38
52
 
39
53
  ## Development
@@ -1,7 +1,4 @@
1
- require "method_matchable/version"
1
+ require 'method_matchable/base'
2
+ require 'method_matchable/version'
2
3
 
3
- module MethodMatchable
4
- def deconstruct_keys(keys)
5
- keys.each_with_object({}) { |k, h| h[k] = send(k) }
6
- end
7
- end
4
+ module MethodMatchable; end
@@ -0,0 +1,9 @@
1
+ module MethodMatchable
2
+ module Base
3
+ def deconstruct_keys(keys)
4
+ keys.each_with_object(defined?(super) ? super(keys).dup : {}) do |k, h|
5
+ h[k] = send(k) if respond_to?(k)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module MethodMatchable
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: method_matchable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - kokuyouwind
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-20 00:00:00.000000000 Z
11
+ date: 2019-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -71,6 +71,7 @@ files:
71
71
  - bin/console
72
72
  - bin/setup
73
73
  - lib/method_matchable.rb
74
+ - lib/method_matchable/base.rb
74
75
  - lib/method_matchable/version.rb
75
76
  - method_matchable.gemspec
76
77
  homepage: https://github.com/kokuyouwind/method_matchable