Sha256: 97f392a621d278f59dc67e5f6ae42d80f5892e62ee05c0555b861eb29749d596
Contents?: true
Size: 914 Bytes
Versions: 22
Compression:
Stored size: 914 Bytes
Contents
class Cl module Merge MERGE = ->(key, lft, rgt) do lft.is_a?(Hash) && rgt.is_a?(Hash) ? lft.merge(rgt, &MERGE) : rgt end def merge(*objs) objs.inject({}) { |lft, rgt| lft.merge(rgt, &MERGE) } end end module Regex def format_regex(str) return str unless str.is_a?(Regexp) "/#{str.to_s.sub('(?-mix:', '').sub(/\)$/, '')}/" end end module Wrap def wrap(str, opts = {}) width = opts[:width] || 80 str.lines.map do |line| line.size > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n").strip : line end.join("\n") end end module Underscore def underscore(string) string.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). downcase end end extend Merge, Regex, Wrap end if RUBY_VERSION == '2.0.0' Array.class_eval do def to_h Hash[self] end end end
Version data entries
22 entries across 22 versions & 1 rubygems