Sha256: 5d90921f74be7d7cb6da6ba08debfb48c769752e5a0e26d1a4289cee1a1f4753

Contents?: true

Size: 907 Bytes

Versions: 3

Compression:

Stored size: 907 Bytes

Contents

# frozen_string_literal: true

module LedgerSync
  module Util
    module Mixins
      module DelegateIterableMethodsMixin
        module ClassMethods
          SHARED_METHODS = %i[
            []
            any?
            count
            each
            empty?
            include?
            map
          ].freeze

          ARRAY_METHODS = (SHARED_METHODS | %i[]).freeze

          HASH_METHODS = (SHARED_METHODS | %i[
            each_value
            fetch
            key?
            keys
            values
          ]).freeze

          def delegate_array_methods_to(delegate_to)
            delegate(*ARRAY_METHODS, to: delegate_to)
          end

          def delegate_hash_methods_to(delegate_to)
            delegate(*HASH_METHODS, to: delegate_to)
          end
        end

        def self.included(base)
          base.extend(ClassMethods)
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-1.4.2 lib/ledger_sync/util/mixins/delegate_iterable_methods_mixin.rb
ledger_sync-1.4.1 lib/ledger_sync/util/mixins/delegate_iterable_methods_mixin.rb
ledger_sync-1.4.0 lib/ledger_sync/util/mixins/delegate_iterable_methods_mixin.rb