forked from freeCodeCamp/freeCodeCamp
-
Notifications
You must be signed in to change notification settings - Fork 2
Ruby Numbers Methods
Quincy Larson edited this page Aug 20, 2016
·
1 revision
In Ruby there are a variety of build in methods you can perform on numbers.
- Use
.even?
to check whether or not an integer is even.
15.even?
4.even?
# returns:
false
true
- Use
.odd?
to check whether or not an integer is odd.
15.odd?
4.odd?
# returns:
true
false
- The
.ceil
method rounds up to the nearest integers.
8.3.ceil
6.7.ceil
# returns:
9
7
- The
.floor
method rounds down to the nearest integers.
8.3.floor
6.7.floor
# returns:
8
6
- Use
.next
to return the next consecutive integer.
15.next
2.next
-4.next
# returns:
16
3
-3
- The
.to_s
method changes an integer into a string.
15.to_s
# returns:
"15"
- The
.gcd
method returns the greatest common denominator of two numbers.
15.gcd(5)
9.gcd(4)
# returns:
5
1
Home | Next |
---|---|
Ruby Numbers Basics | Ruby Numbers Operations |
Learn to code and help nonprofits. Join our open source community in 15 seconds at http://freecodecamp.com
Follow our Medium blog
Follow Quincy on Quora
Follow us on Twitter
Like us on Facebook
And be sure to click the "Star" button in the upper right of this page.
New to Free Code Camp?
JS Concepts
JS Language Reference
- arguments
- Array.prototype.filter
- Array.prototype.indexOf
- Array.prototype.map
- Array.prototype.pop
- Array.prototype.push
- Array.prototype.shift
- Array.prototype.slice
- Array.prototype.some
- Array.prototype.toString
- Boolean
- for loop
- for..in loop
- for..of loop
- String.prototype.split
- String.prototype.toLowerCase
- String.prototype.toUpperCase
- undefined
Other Links