diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2015-05-13 19:15:28 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2015-05-13 19:15:42 +0200 |
commit | e54277a45da3c86fecdfa930663d7692fd083daa (patch) | |
tree | bfdb6c599930e4a2ab4ba258a207b95c3ad3eda3 /activesupport/lib | |
parent | 07ad2a945b6e9ec9421746294bd0b6787fd0ecdd (diff) | |
download | rails-e54277a45da3c86fecdfa930663d7692fd083daa.tar.gz rails-e54277a45da3c86fecdfa930663d7692fd083daa.tar.bz2 rails-e54277a45da3c86fecdfa930663d7692fd083daa.zip |
Add Integer#positive? and Integer#negative? query methods in the vein of Fixnum#zero?
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/integer.rb | 1 | ||||
-rw-r--r-- | activesupport/lib/active_support/core_ext/integer/inquiry.rb | 19 |
2 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/integer.rb b/activesupport/lib/active_support/core_ext/integer.rb index a44a1b4c74..f5b185b42b 100644 --- a/activesupport/lib/active_support/core_ext/integer.rb +++ b/activesupport/lib/active_support/core_ext/integer.rb @@ -1,3 +1,4 @@ require 'active_support/core_ext/integer/multiple' require 'active_support/core_ext/integer/inflections' +require 'active_support/core_ext/integer/inquiry' require 'active_support/core_ext/integer/time' diff --git a/activesupport/lib/active_support/core_ext/integer/inquiry.rb b/activesupport/lib/active_support/core_ext/integer/inquiry.rb new file mode 100644 index 0000000000..dc710b74d0 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/integer/inquiry.rb @@ -0,0 +1,19 @@ +class Integer + # Returns true if the number is positive. + # + # 1.positive? # => true + # 0.positive? # => false + # -1.positive? # => false + def positive? + self > 0 + end + + # Returns true if the number is positive. + # + # -1.positive? # => true + # 0.positive? # => false + # 1.positive? # => false + def negative? + self < 0 + end +end |