Sha256: d08ff17d65c8c4878e4e4f9a8ab4297359176b80ed9c73c8b8b65438510e2fab
Contents?: true
Size: 746 Bytes
Versions: 7
Compression:
Stored size: 746 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 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
7 entries across 7 versions & 1 rubygems
Version | Path |
---|---|
cl-0.1.12 | lib/cl/helper.rb |
cl-0.1.11 | lib/cl/helper.rb |
cl-0.1.10 | lib/cl/helper.rb |
cl-0.1.9 | lib/cl/helper.rb |
cl-0.1.8 | lib/cl/helper.rb |
cl-0.1.7 | lib/cl/helper.rb |
cl-0.1.6 | lib/cl/helper.rb |