Module: SnakyHash::Serializer::BackportedInstanceMethods — Documentation by YARD 0.9.37

# Module: SnakyHash::Serializer::BackportedInstanceMethods

Defined in:
  lib/snaky_hash/serializer.rb

## Overview

Provides backported methods for older Ruby versions

## Instance Method Summary collapse

- #transform_values {|Object| ... } ⇒ Hash, Enumerator

  :nocov: Transforms values of a hash using the given block.

## Instance Method Details

### #transform_values {|Object| ... } ⇒ `Hash`, `Enumerator`

Note:

This will be run in CI on Ruby 2.3, but we only collect coverage from current Ruby
Rails <= 5.2 had a transform_values method, which was added to Ruby in version 2.4.
This method is a backport of that original Rails method for Ruby 2.2 and 2.3.

:nocov:
Transforms values of a hash using the given block

Yields:

- (`Object`) —

  block to transform each value

Returns:

- (`Hash`) —

  new hash with transformed values

- (`Enumerator`) —

  if no block given

    99
    100
    101
    102
    103
    104
    105
    106
    107
    # File 'lib/snaky_hash/serializer.rb', line 99

    def transform_values(&block)
      return enum_for(:transform_values) { size } unless block_given?
      return {} if empty?
      result = self.class.new
      each do |key, value|
        result[key] = yield(value)
      end
      result
    end