Sha256: 4e1279f412a962ff862381481da60f73efc01d4e8701e8b58de405da05931233

Contents?: true

Size: 535 Bytes

Versions: 2

Compression:

Stored size: 535 Bytes

Contents

module ActiveEnumerable
  # @private
  class MethodCaller
    attr_reader :object, :raise_no_method

    def initialize(object, raise_no_method: true)
      @object          = object
      @raise_no_method = raise_no_method
    end

    def call(method)
      if object.is_a? Hash
        object.fetch(method)
      else
        object.public_send(method)
      end
    rescue NoMethodError => e
      raise e if raise_no_method
    rescue KeyError => e
      raise e, "#{e.message} for #{object}" if raise_no_method
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
active_enumerable-1.0.0 lib/active_enumerable/method_caller.rb
active_enumerable-0.2.0 lib/active_enumerable/method_caller.rb