lib/forwardable/extended.rb
def def_modern_delegator(accessor, method, alias_ = method, args: \
        { :before => [], :after => [] }, **kwd)

      prefix, suffix, wrap = prepare_delegate(**kwd)
      args = { :before => args } unless args.is_a?(Hash)
      b = [args[:before]].flatten.compact.map(&:to_s).join(", ")
      a = [args[ :after]].flatten.compact.map(&:to_s).join(", ")
      b = b + ", " unless args[:before].nil? || args[:before].empty?
      a = ", " + a unless args[ :after].nil? || args[ :after].empty?
      alias_ = alias_.to_s.gsub(/\?$/, "") if suffix

      class_eval delegate_debug(<<-STR), __FILE__, __LINE__ - 10
        def #{alias_}#{suffix}(*args, &block)
          #{wrap}(#{prefix}#{accessor}.send(
            #{method.inspect}, #{b}*args#{a}, &block
          ))

        rescue Exception
          if !Forwardable.debug && $@ && $@.respond_to?(:delete_if)
            $@.delete_if do |source|
              source =~ %r"#{Regexp.escape(__FILE__)}"o
            end
          end

          raise
        end
      STR
    end
def def_modern_delegator(accessor, method, alias_ = method, args: \
        { :before => [], :after => [] }, **kwd)

      prefix, suffix, wrap = prepare_delegate(**kwd)
      args = { :before => args } unless args.is_a?(Hash)
      b = [args[:before]].flatten.compact.map(&:to_s).join(", ")
      a = [args[ :after]].flatten.compact.map(&:to_s).join(", ")
      b = b + ", " unless args[:before].nil? || args[:before].empty?
      a = ", " + a unless args[ :after].nil? || args[ :after].empty?
      alias_ = alias_.to_s.gsub(/\?$/, "") if suffix

      class_eval delegate_debug(<<-STR), __FILE__, __LINE__ - 10
        def #{alias_}#{suffix}(*args, &block)
          #{wrap}(#{prefix}#{accessor}.send(
            #{method.inspect}, #{b}*args#{a}, &block
          ))

        rescue Exception
          if !Forwardable.debug && $@ && $@.respond_to?(:delete_if)
            $@.delete_if do |source|
              source =~ %r"#{Regexp.escape(__FILE__)}"o
            end
          end

          raise
        end
      STR
    end
def def_modern_delegator ( accessor , method , alias_ = method , args : { :before => [ ] , :after => [ ] } , ** kwd ) prefix , suffix , wrap = prepare_delegate ( ** kwd ) args = { :before => args } unless args . is_a? ( Hash ) b = [ args [ :before ] ] . flatten . compact . map ( :to_s ) . join ( ", " ) a = [ args [ :after ] ] . flatten . compact . map ( :to_s ) . join ( ", " ) b = b + ", " unless args [ :before ] . nil? || args [ :before ] . empty? a = ", " + a unless args [ :after ] . nil? || args [ :after ] . empty? alias_ = alias_ . to_s . gsub ( / \? / , "" ) if suffix class_eval delegate_debug ( <<-STR ) , __FILE__ , __LINE__ - 10 #{ alias_ } #{ suffix } #{ wrap } #{ prefix } #{ accessor } #{ method . inspect } #{ b } #{ a } #{ Regexp . escape ( __FILE__ ) } STR end
------------------------------------------------------------------------
 Like def_delegator but allows you to send args and do other stuff.
 ------------------------------------------------------------------------
------------------------------------------------------------------------ Like def_delegator but allows you to send args and do other stuff . ------------------------------------------------------------------------