Sha256: f91d98f09fe0a37d916627c4df2334ec9b107a2535ecbadfe81e0c40c07d18d4

Contents?: true

Size: 435 Bytes

Versions: 17

Compression:

Stored size: 435 Bytes

Contents

class Class
  # TODO: Check for arity
  def forward_methods(*methods, object)
    for method in Array(methods).flatten
      if method.to_s.end_with?("=")
        src = "def #{method}(args) raise if #{object}.nil?; #{object}.#{method}(args) end"
      else
        src = "def #{method}(*args) #{object}&.#{method}(*args) end"
      end
      class_eval(src)
    end
  end

  def forward_method(*args) forward_methods(*args) end
end


Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
prick-0.19.0 lib/ext/forward_method.rb
prick-0.18.0 lib/ext/forward_method.rb
prick-0.17.0 lib/ext/forward_method.rb
prick-0.16.0 lib/ext/forward_method.rb
prick-0.15.0 lib/ext/forward_method.rb
prick-0.14.0 lib/ext/forward_method.rb
prick-0.13.0 lib/ext/forward_method.rb
prick-0.12.0 lib/ext/forward_method.rb
prick-0.11.0 lib/ext/forward_method.rb
prick-0.10.0 lib/ext/forward_method.rb
prick-0.9.0 lib/ext/forward_method.rb
prick-0.8.0 lib/ext/forward_method.rb
prick-0.7.0 lib/ext/forward_method.rb
prick-0.6.0 lib/ext/forward_method.rb
prick-0.5.0 lib/ext/forward_method.rb
prick-0.4.0 lib/ext/forward_method.rb
prick-0.3.0 lib/ext/forward_method.rb