lib/logging/utils.rb in logging-1.8.2 vs lib/logging/utils.rb in logging-2.0.0

- old
+ new

@@ -1,64 +1,22 @@ require 'thread' require 'rbconfig' # -------------------------------------------------------------------------- -class Hash - - # call-seq: - # getopt( key, default = nil, :as => class ) - # - # Returns the value associated with the _key_. If the has does not contain - # the _key_, then the _default_ value is returned. - # - # Optionally, the value can be converted into to an instance of the given - # _class_. The supported classes are: - # - # Integer - # Float - # Array - # String - # Symbol - # - # If the value is +nil+, then no conversion will be performed. - # - def getopt( *args ) - opts = args.last.instance_of?(Hash) ? args.pop : {} - key, default = args - - val = if has_key?(key); self[key] - elsif has_key?(key.to_s); self[key.to_s] - elsif has_key?(key.to_s.intern); self[key.to_s.intern] - else default end - - return if val.nil? - return val unless opts.has_key?(:as) - - case opts[:as].name.intern - when :Integer; Integer(val) - when :Float; Float(val) - when :Array; Array(val) - when :String; String(val) - when :Symbol; String(val).intern - else val end - end -end - -# -------------------------------------------------------------------------- class String # call-seq: - # reduce( width, ellipses = '...' ) #=> string + # shrink( width, ellipses = '...' ) #=> string # - # Reduce the size of the current string to the given _width_ by removing + # Shrink the size of the current string to the given _width_ by removing # characters from the middle of the string and replacing them with # _ellipses_. If the _width_ is greater than the length of the string, the # string is returned unchanged. If the _width_ is less than the length of # the _ellipses_, then the _ellipses_ are returned. # - def reduce( width, ellipses = '...') + def shrink( width, ellipses = '...') raise ArgumentError, "width cannot be negative: #{width}" if width < 0 return self if length <= width remove = length - width + ellipses.length @@ -107,29 +65,10 @@ return 'anonymous' end end # -------------------------------------------------------------------------- -module Kernel - - # call-seq: - # require?( string ) - # - # Attempt to the load the library named _string_ using the standard - # Kernel#require method. Returns +true+ if the library was successfully - # loaded. Returns +false+ if the library could not be loaded. This method - # will never raise an exception. - # - def require?( string ) - require string - return true - rescue LoadError - return false - end -end # module Kernel - -# -------------------------------------------------------------------------- class File # Returns <tt>true</tt> if another process holds an exclusive lock on the # file. Returns <tt>false</tt> if this is not the case. # @@ -209,10 +148,10 @@ def initialize super @locker = nil end - alias :original_synchronize :synchronize + alias_method :original_synchronize, :synchronize def synchronize if @locker == Thread.current yield else