Sha256: 932223d928f52288e81466a2122f62b60e9df64947229620cfe6c898a6bc7531

Contents?: true

Size: 378 Bytes

Versions: 27

Compression:

Stored size: 378 Bytes

Contents

class Module
  def foobara_delegate(*method_names, to:, allow_nil: false)
    method_names.each do |method_name|
      define_method method_name do |*args, **opts, &block|
        target = to.is_a?(::Symbol) || to.is_a?(::String) ? send(to) : to
        return nil if target.nil? && allow_nil

        target.send(method_name, *args, **opts, &block)
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
foobara-0.0.7 projects/delegate/src/extensions/module.rb
foobara-0.0.6 projects/delegate/src/extensions/module.rb
foobara-0.0.5 projects/delegate/src/extensions/module.rb
foobara-0.0.4 projects/delegate/src/extensions/module.rb
foobara-0.0.3 projects/delegate/src/extensions/module.rb
foobara-0.0.2 projects/delegate/src/extensions/module.rb
foobara-0.0.1 projects/delegate/src/extensions/module.rb