-
Notifications
You must be signed in to change notification settings - Fork 21.8k
Commit
… of Fixnum#zero?
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
# | ||
# -1.positive? # => true | ||
# 0.positive? # => false | ||
# 1.positive? # => false | ||
def negative? | ||
self < 0 | ||
end | ||
end |
11 comments
on commit e54277a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome, thanks!
By the way, could we get a #prime?
too?
(but seriously, '#non_zero?` would be awesome too!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought AS additions are frozen for code not used internally in Rails.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh, thanks for clarification @rafaelfranca.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cheerfulstoic #prime?
comes from Ruby standard library already. Try requiring prime
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Such great addition. Why stopping here? I think Ruby core lib needs this love too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gsamokovarov Thanks, I had forgotten about that! I was joking about #prime?
, but was (more) serious about #non_zero?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cheerfulstoic ruby has nonzero?
already.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, so it does! I'll shut up now ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For prime numbers, already exists prime.
Nice add!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made this gem as a joke four years ago, and now Rails got serious about it. Marvelous!
Could change this doc to reflect method name ? /cc @dhh