Sha256: d2adad03c51bbc9abb4db99c5d460cc19eff9b71cdd0cdeb992ce657c9e9f81e
Contents?: true
Size: 1.43 KB
Versions: 7
Compression:
Stored size: 1.43 KB
Contents
module DuckPuncher module Ducks module Object def clone! Marshal.load Marshal.dump self end unless defined? clone! def require!(file_or_gem, version = '') if DuckPuncher::GemInstaller.new.perform(file_or_gem, version) require file_or_gem.tr('-', '/') end end # @description Returns a new decorated version of ourself with the punches mixed in (adds ancestors decorators) # @return [<self.class>Delegator] def punch DuckPuncher.decorate self, DuckPuncher.undecorate(self).class end # @description Adds the duck punches to the current object (meant to be used on instances, careful with nil and numbers!) # @return self def punch! target = DuckPuncher.undecorate(self).class DuckPuncher::Ducks.load_mods(target).each { |mod| self.extend mod } self end # @param [Integer] trace The number of lines from the stack trace to print (nil) def echo(trace = nil) p self puts caller_locations.take(trace).map { |l| l.to_s.prepend('* ') }.join("\n") if trace self end def track begin require 'object_tracker' || raise(LoadError) rescue LoadError DuckPuncher.(Object, only: :require!) unless respond_to? :require! require! 'object_tracker' end extend ::ObjectTracker track_all! end end end end
Version data entries
7 entries across 7 versions & 1 rubygems