delegate 0.5.0 → 0.6.1
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 +22 -14
- 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: a8537e6d97d8707e29a37239baccb6be764d37aadc748d7bc525ca6f426e3bdc
|
|
4
|
+
data.tar.gz: 0cb5bcee38006db2d540ed5ea84fa8f9e08e71abbfc6875f2931153fa6c89a23
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3ba0a2a005054b94f0789a242300e6e5f63cf5133a58bdd751ab6edcce84b129cf12a181b7e782577dd1eb44b633edde25ffc8dd2ea25aa547f27e4f3f9a8d80
|
|
7
|
+
data.tar.gz: f0e941c1b05ff024b2dbc2d864bcda01f1c12db5d8304bfda2aba988f42b875d76fc92541415911dd9b917587fdc01b16beac340426ea8e2999cb46077f7efc0
|
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.1"
|
|
44
44
|
|
|
45
45
|
kernel = ::Kernel.dup
|
|
46
46
|
kernel.class_eval do
|
|
@@ -345,16 +345,10 @@ class SimpleDelegator < Delegator
|
|
|
345
345
|
end
|
|
346
346
|
|
|
347
347
|
def Delegator.delegating_block(mid) # :nodoc:
|
|
348
|
-
|
|
348
|
+
lambda do |*args, &block|
|
|
349
349
|
target = self.__getobj__
|
|
350
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
|
|
357
|
-
end
|
|
351
|
+
end.ruby2_keywords
|
|
358
352
|
end
|
|
359
353
|
|
|
360
354
|
#
|
|
@@ -405,6 +399,17 @@ def DelegateClass(superclass, &block)
|
|
|
405
399
|
protected_instance_methods -= ignores
|
|
406
400
|
public_instance_methods = superclass.public_instance_methods
|
|
407
401
|
public_instance_methods -= ignores
|
|
402
|
+
|
|
403
|
+
normal, special = public_instance_methods.partition { |m| m.match?(/\A[a-zA-Z]\w*[!\?]?\z/) }
|
|
404
|
+
|
|
405
|
+
source = normal.map do |method|
|
|
406
|
+
"def #{method}(...); __getobj__.#{method}(...); end"
|
|
407
|
+
end
|
|
408
|
+
|
|
409
|
+
protected_instance_methods.each do |method|
|
|
410
|
+
source << "def #{method}(...); __getobj__.__send__(#{method.inspect}, ...); end"
|
|
411
|
+
end
|
|
412
|
+
|
|
408
413
|
klass.module_eval do
|
|
409
414
|
def __getobj__ # :nodoc:
|
|
410
415
|
unless defined?(@delegate_dc_obj)
|
|
@@ -413,18 +418,21 @@ def DelegateClass(superclass, &block)
|
|
|
413
418
|
end
|
|
414
419
|
@delegate_dc_obj
|
|
415
420
|
end
|
|
421
|
+
|
|
416
422
|
def __setobj__(obj) # :nodoc:
|
|
417
423
|
__raise__ ::ArgumentError, "cannot delegate to self" if self.equal?(obj)
|
|
418
424
|
@delegate_dc_obj = obj
|
|
419
425
|
end
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
public_instance_methods.each do |method|
|
|
426
|
+
|
|
427
|
+
class_eval(source.join(";"), __FILE__, __LINE__)
|
|
428
|
+
|
|
429
|
+
special.each do |method|
|
|
425
430
|
define_method(method, Delegator.delegating_block(method))
|
|
426
431
|
end
|
|
432
|
+
|
|
433
|
+
protected(*protected_instance_methods)
|
|
427
434
|
end
|
|
435
|
+
|
|
428
436
|
klass.define_singleton_method :public_instance_methods do |all=true|
|
|
429
437
|
super(all) | superclass.public_instance_methods
|
|
430
438
|
end
|