Sha256: 8f87d5c3574b1a48132e7a0e4aee4fe8f2fc17af7b59e4ac35d5b09f34c33694

Contents?: true

Size: 578 Bytes

Versions: 20

Compression:

Stored size: 578 Bytes

Contents

# frozen_string_literal: true

String.class_eval do
  # Calls `to_i` and returns the value if it is negative
  #
  # @return [Integer, Nil]
  #
  def to_negative_i
    val = to_i

    return unless val.negative?

    val
  end
end

Numeric.class_eval do
  # Calls `to_i` and returns the value if it is negative
  #
  # @return [Integer, Nil]
  #
  def to_negative_i
    val = to_i

    return unless val.negative?

    val
  end
end

NilClass.class_eval do
  # Calls `to_i` and returns the value if it is negative
  #
  # @return [Nil]
  #
  def to_negative_i
    nil
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
ruby-rails-extensions-2.1.1 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.14 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.13 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.12 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.11 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.10 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.9 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.8 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.7 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.6 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.5 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.4 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.3 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.2 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.1.0.pre.rc.1 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.0.1 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.0.1.pre.rc.1 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.0.0 lib/ruby-rails-extensions/extensions/to_negative_i.rb
ruby-rails-extensions-2.0.0.pre.rc.1 lib/ruby-rails-extensions/extensions/to_negative_i.rb