Sha256: 33af829888f29570c1c9493e75f7ed52a46c88d48572bf4b15116fe4e66dcbef

Contents?: true

Size: 506 Bytes

Versions: 6

Compression:

Stored size: 506 Bytes

Contents

# frozen_string_literal: true

Range.class_eval do
  unless method_defined?(:zero?)
    # Checks if the whole range is zero.
    #
    # @raise [RubyRailsExtensions::Errors::NonNumericError]
    #
    # @return [Boolean]
    #
    def zero?
      unless self.begin.is_a?(Numeric)
        raise(
          RubyRailsExtensions::Errors::NonNumericError,
          "Wrong range type (given #{self.begin.class}, expected Numeric)"
        )
      end

      self.begin.zero? && self.end.zero?
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
ruby-rails-extensions-1.1.1 lib/ruby-rails-extensions/extensions/zero_range.rb
ruby-rails-extensions-1.1.1.pre.rc.1 lib/ruby-rails-extensions/extensions/zero_range.rb
ruby-rails-extensions-0.2.0 lib/ruby-rails-extensions/extensions/zero_range.rb
ruby-rails-extensions-0.2.0.pre.rc.1 lib/ruby-rails-extensions/extensions/zero_range.rb
ruby-rails-extensions-1.1.0 lib/ruby-rails-extensions/extensions/zero_range.rb
ruby-rails-extensions-1.1.0.pre.rc.1 lib/ruby-rails-extensions/extensions/zero_range.rb