forward_to 0.2.0 → 0.3.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: 8a1ff9f7cbe1f4953d0afdfa5da319833852fd9c8b747f42c36b366738f386d2
4
- data.tar.gz: 2ee5d34d5709f717a6edb36286432551d3088a42e3d567309c1edc1d29b6dcba
3
+ metadata.gz: '079c056657ce3bbdeba3086c185a38723c13ef0b357780a56ad5839e249f1ffe'
4
+ data.tar.gz: bc76638c1b0d7d480630d764c17078f4588684c1d00a0c9a820e6c9dfa0a4b59
5
5
  SHA512:
6
- metadata.gz: 70e52e898f4a172cfc148dbd927dce3331b641901ffa2a67edee745861bfc1ebde1c51483633bfff30c9fc4fea7630bc457dd9e90a24493a8e2a4518020a1c66
7
- data.tar.gz: 8a9954ab4cfb321bdc3d3e2051330f0e49fe58f6729766deba14c8842de826551a9574c9b0c965be7a7a834511a37386d28c7cb58c1a5698402e08fd7bfc3e08
6
+ metadata.gz: c9b47190963da620d6da24fbef310fa40b9b522da5df19967e363f4a891f3f8db8d8253fd56172a424af9f1cbd0aad7a3c68ed03ebda4fe8e9591250deb56d71
7
+ data.tar.gz: 782a9d3e395a922e4ada9352095384ec3b97fc2aa30223a59eabe10e4023719c943654131949387b4565ea1b59a4ec48683d06e7c348c995b4e1bf2b741b12a0
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ForwardTo
4
- VERSION = "0.2.0"
4
+ VERSION = "0.3.0"
5
5
  end
data/lib/forward_to.rb CHANGED
@@ -20,16 +20,22 @@ module ForwardTo
20
20
  #
21
21
  # a = MyArray.new
22
22
  # a.size # -> 0
23
+ # a.empty? # -> true
24
+ # a[0] = 1
25
+ # a[0] # -> 1
23
26
  #
24
27
  # The target of #forward_to can be a method or a member (@variable) but has
25
28
  # to be a symbol
26
29
  #
27
30
  def forward_to(target, *methods)
28
31
  for method in Array(methods).flatten
29
- if method =~ /=$/
30
- class_eval("def #{method}(*args) #{target}&.#{method}(*args) end")
31
- else
32
- class_eval("def #{method}(*args, &block) #{target}&.#{method}(*args, &block) end")
32
+ case method
33
+ when /\[\]=/
34
+ class_eval("def #{method}(*args) #{target}&.#{method}(*args) end")
35
+ when /=$/
36
+ class_eval("def #{method}(args) #{target}&.#{method}(args) end")
37
+ else
38
+ class_eval("def #{method}(*args, &block) #{target}&.#{method}(*args, &block) end")
33
39
  end
34
40
  end
35
41
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: forward_to
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-20 00:00:00.000000000 Z
11
+ date: 2022-09-03 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Simple forwarding of methods
14
14
  email: