Sha256: 9b39062e4fb17c09dd8750ae6302b84678ee8d4b797b5e29a5504023bd9c6e24
Contents?: true
Size: 1.18 KB
Versions: 2
Compression:
Stored size: 1.18 KB
Contents
# Enumerable extensions. module Enumerable # Invokes the specified method for each item, along with the supplied # arguments. def send_each(sym, *args) each {|i| i.send(sym, *args)} end end # Range extensions class Range # Returns the interval between the beginning and end of the range. def interval last - first end end # Object extensions class Object # Returns true if the object is a object of one of the classes def is_one_of?(*classes) classes.each {|c| return c if is_a?(c)} nil end # Objects are blank if they respond true to empty? def blank? nil? || (respond_to?(:empty?) && empty?) end end class Numeric # Numerics are never blank (not even 0) def blank? false end end class NilClass # nil is always blank def blank? true end end class TrueClass # true is never blank def blank? false end end class FalseClass # false is always blank def blank? true end end class String BLANK_STRING_REGEXP = /\A\s*\z/ # Strings are blank if they are empty or include only whitespace def blank? empty? || BLANK_STRING_REGEXP.match(self) end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sequel_core-1.5.0 | lib/sequel_core/core_ext.rb |
sequel_core-1.5.1 | lib/sequel_core/core_ext.rb |