Sha256: ca0a8c2c91dd49fc3ffa30a1b7d6f129139781acaae6526a56247b91283cec69
Contents?: true
Size: 842 Bytes
Versions: 18
Compression:
Stored size: 842 Bytes
Contents
# frozen_string_literal: true module Anyway module Ext # Convert Hash with mixed array and hash values to an # array of paths. module FlattenNames refine ::Array do def flatten_names(prefix, buf) if empty? buf << :"#{prefix}" return buf end each_with_object(buf) do |name, acc| if name.is_a?(::Symbol) acc << :"#{prefix}.#{name}" else name.flatten_names(prefix, acc) end end end end refine ::Hash do def flatten_names(prefix = nil, buf = []) each_with_object(buf) do |(k, v), acc| parent = prefix ? "#{prefix}.#{k}" : k v.flatten_names(parent, acc) end end end using self end end end
Version data entries
18 entries across 18 versions & 2 rubygems