Sha256: 4d8358fd43c9156fca8d6f09dbdcb2e74919148ea6708fe90dda4cc4ce470fb5
Contents?: true
Size: 1.55 KB
Versions: 5
Compression:
Stored size: 1.55 KB
Contents
# frozen_string_literal: true begin require 'active_support/core_ext/hash/keys' require 'active_support/core_ext/hash/deep_merge' rescue LoadError class Hash unless {}.respond_to?(:slice) def slice(*keys) keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true) keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if key?(k) } end end unless {}.respond_to?(:slice!) def slice!(*keys) keys.map! { |key| convert_key(key) } if respond_to?(:convert_key, true) omit = slice(*self.keys - keys) hash = slice(*keys) hash.default = default hash.default_proc = default_proc if default_proc replace(hash) omit end end end end class Array unless [].respond_to?(:extract_options!) def extract_options! if last.is_a?(Hash) && last.instance_of?(Hash) pop else {} end end end end class String unless ''.respond_to?(:classify) def classify camelize(sub(/.*\./, '')) end end unless ''.respond_to?(:camelize) def camelize(uppercase_first_letter = true) string = self string = if uppercase_first_letter string.sub(/^[a-z\d]*/) { $&.capitalize } else string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase } end string.gsub!(%r{(?:_|(\/))([a-z\d]*)}i) do "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}" end string.gsub!(%r{/}, '::') string end end end
Version data entries
5 entries across 5 versions & 1 rubygems