Skip to content
Closed
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
28 changes: 15 additions & 13 deletions lib/forwardable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ class << self
# delegate [method, method, ...] => accessor
#
def instance_delegate(hash)
hash.each{ |methods, accessor|
methods = [methods] unless methods.respond_to?(:each)
methods.each{ |method|
def_instance_delegator(accessor, method)
}
}
hash.each do |methods, accessor|
unless defined?(methods.each)
def_instance_delegator(accessor, methods)
else
methods.each {|method| def_instance_delegator(accessor, method)}
end
end
end

#
Expand Down Expand Up @@ -204,7 +205,7 @@ def self._delegator_method(obj, accessor, method, ali)
mesg = "#{Module === obj ? obj : obj.class}\##{ali} at #{loc.path}:#{loc.lineno} forwarding to private method "
method_call = "#{<<-"begin;"}\n#{<<-"end;".chomp}"
begin;
unless ::Kernel.instance_method(:respond_to?).bind(_).call(:"#{method}")
unless defined? _.#{method}
::Kernel.warn "\#{caller_locations(1)[0]}: "#{mesg.dump}"\#{_.class}"'##{method}'
_#{method_call}
else
Expand Down Expand Up @@ -261,12 +262,13 @@ module SingleForwardable
# delegate [method, method, ...] => accessor
#
def single_delegate(hash)
hash.each{ |methods, accessor|
methods = [methods] unless methods.respond_to?(:each)
methods.each{ |method|
def_single_delegator(accessor, method)
}
}
hash.each do |methods, accessor|
unless defined?(methods.each)
def_single_delegator(accessor, methods)
else
methods.each {|method| def_single_delegator(accessor, method)}
end
end
end

#
Expand Down