delegate 0.5.0 → 0.6.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 +4 -4
- data/lib/delegate.rb +28 -16
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9fd09bc1c57e6112ca448780e877b5a07681c642937cf2457895be0dd05f990a
|
|
4
|
+
data.tar.gz: c9d806a0105bdd3a7ea904d8c829687bec4bf57fba9056ee8397186b4f05f108
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aff48e6ba7051a1d421248d0a67cd760d3c680d5df7cb5778636d5d843a4afc3a96b10469872acfa51a702eb21c9f65df41cd205878975089dfecb0aa7c42853
|
|
7
|
+
data.tar.gz: 3482081f54f59d708691a45065f80f676d77571fc986f5f92c823c24fea6281f9b373f2a00095522fe0afc57803084864a647e06546791996affbdcb1c2f17d0
|
data/lib/delegate.rb
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
#
|
|
41
41
|
class Delegator < BasicObject
|
|
42
42
|
# The version string
|
|
43
|
-
VERSION = "0.
|
|
43
|
+
VERSION = "0.6.0"
|
|
44
44
|
|
|
45
45
|
kernel = ::Kernel.dup
|
|
46
46
|
kernel.class_eval do
|
|
@@ -344,17 +344,15 @@ class SimpleDelegator < Delegator
|
|
|
344
344
|
end
|
|
345
345
|
end
|
|
346
346
|
|
|
347
|
-
def Delegator.
|
|
348
|
-
|
|
347
|
+
def Delegator.delegating_code(mid) # :nodoc:
|
|
348
|
+
line = __LINE__+2
|
|
349
|
+
src = <<~RUBY
|
|
350
|
+
ruby2_keywords def #{mid}(*args, &block)
|
|
349
351
|
target = self.__getobj__
|
|
350
|
-
target.__send__(mid, *args, &block)
|
|
351
|
-
end
|
|
352
|
-
prok.ruby2_keywords
|
|
353
|
-
if defined?(Ractor.shareable_proc)
|
|
354
|
-
Ractor.shareable_proc(&prok)
|
|
355
|
-
else
|
|
356
|
-
prok
|
|
352
|
+
target.__send__(:'#{mid}', *args, &block)
|
|
357
353
|
end
|
|
354
|
+
RUBY
|
|
355
|
+
[src, __FILE__, line]
|
|
358
356
|
end
|
|
359
357
|
|
|
360
358
|
#
|
|
@@ -405,6 +403,17 @@ def DelegateClass(superclass, &block)
|
|
|
405
403
|
protected_instance_methods -= ignores
|
|
406
404
|
public_instance_methods = superclass.public_instance_methods
|
|
407
405
|
public_instance_methods -= ignores
|
|
406
|
+
|
|
407
|
+
normal, special = public_instance_methods.partition { |m| m.match?(/\A[a-zA-Z]\w*[!\?]?\z/) }
|
|
408
|
+
|
|
409
|
+
source = normal.map do |method|
|
|
410
|
+
"def #{method}(...); __getobj__.#{method}(...); end"
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
protected_instance_methods.each do |method|
|
|
414
|
+
source << "def #{method}(...); __getobj__.__send__(#{method.inspect}, ...); end"
|
|
415
|
+
end
|
|
416
|
+
|
|
408
417
|
klass.module_eval do
|
|
409
418
|
def __getobj__ # :nodoc:
|
|
410
419
|
unless defined?(@delegate_dc_obj)
|
|
@@ -413,18 +422,21 @@ def DelegateClass(superclass, &block)
|
|
|
413
422
|
end
|
|
414
423
|
@delegate_dc_obj
|
|
415
424
|
end
|
|
425
|
+
|
|
416
426
|
def __setobj__(obj) # :nodoc:
|
|
417
427
|
__raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
|
|
418
428
|
@delegate_dc_obj = obj
|
|
419
429
|
end
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
define_method(method, Delegator.delegating_block(method))
|
|
430
|
+
|
|
431
|
+
class_eval(source.join(";"), __FILE__, __LINE__)
|
|
432
|
+
|
|
433
|
+
special.each do |method|
|
|
434
|
+
module_eval(*Delegator.delegating_code(method))
|
|
426
435
|
end
|
|
436
|
+
|
|
437
|
+
protected(*protected_instance_methods)
|
|
427
438
|
end
|
|
439
|
+
|
|
428
440
|
klass.define_singleton_method :public_instance_methods do |all=true|
|
|
429
441
|
super(all) | superclass.public_instance_methods
|
|
430
442
|
end
|