Sha256: ed08447f99692dc3b71d4165ec06a61e17ed96b098d13ddabfda60bd3cbf9b5a

Contents?: true

Size: 699 Bytes

Versions: 2

Compression:

Stored size: 699 Bytes

Contents

# frozen_string_literal: true

module KeyTree
  # KeyTree refinements to core classes
  module Refinements
    refine Array do
      def to_key_forest
        Forest[*map(&:to_key_wood)]
      end
      alias_method :to_key_wood, :to_key_forest

      def to_key_path
        Path.new(self)
      end
    end

    refine Hash do
      def to_key_tree
        Tree[self]
      end
      alias_method :to_key_wood, :to_key_tree
    end

    refine String do
      def to_key_path
        split('.').to_key_path
      end
    end

    refine Symbol do
      def to_key_path
        to_s.to_key_path
      end
    end
  end
end

require_relative 'forest'
require_relative 'path'
require_relative 'tree'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
key_tree-0.8.0 lib/key_tree/refinements.rb
key_tree-0.7.0 lib/key_tree/refinements.rb