Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/forwardable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ def def_instance_delegator(accessor, method, ali = method)

# If it's not a class or module, it's an instance
mod = Module === self ? self : singleton_class
ret = mod.module_eval(&gen)
mod.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
ret
mod.module_eval(&gen)
end

alias delegate instance_delegate
Expand All @@ -209,7 +207,8 @@ def self._delegator_method(obj, accessor, method, ali)
accessor = "#{accessor}()"
end

method_call = ".__send__(:#{method}, *args, &block)"
args = RUBY_VERSION >= '2.7' ? '...' : '*args, &block'
method_call = ".__send__(:#{method}, #{args})"
if _valid_method?(method)
loc, = caller_locations(2,1)
pre = "_ ="
Expand All @@ -220,15 +219,15 @@ def self._delegator_method(obj, accessor, method, ali)
::Kernel.warn #{mesg.dump}"\#{_.class}"'##{method}', uplevel: 1
_#{method_call}
else
_.#{method}(*args, &block)
_.#{method}(#{args})
end
end;
end

_compile_method("#{<<-"begin;"}\n#{<<-"end;"}", __FILE__, __LINE__+1)
begin;
proc do
def #{ali}(*args, &block)
def #{ali}(#{args})
#{pre}
begin
#{accessor}
Expand Down Expand Up @@ -310,9 +309,7 @@ def def_single_delegators(accessor, *methods)
def def_single_delegator(accessor, method, ali = method)
gen = Forwardable._delegator_method(self, accessor, method, ali)

ret = instance_eval(&gen)
singleton_class.__send__(:ruby2_keywords, ali) if RUBY_VERSION >= '2.7'
ret
instance_eval(&gen)
end

alias delegate single_delegate
Expand Down