Class: Integer
Overview
Class Method Summary (collapse)
-
+ induced_from
Convert obj to an Integer.
Instance Method Summary (collapse)
-
- ceil
As int is already an Integer, all these methods simply return the receiver.
-
- chr
Returns a string containing the character represented by the receiver's value according to encoding.
-
- denominator
Returns 1.
-
- downto
Iterates block, passing decreasing values from int down to and including limit.
-
- even?
Returns true if int is an even number.
-
- floor
As int is already an Integer, all these methods simply return the receiver.
-
- gcd
Returns the greatest common divisor (always positive).
-
- gcdlcm
Returns an array; [int.gcd(int2), int.lcm(int2)].
-
- integer?
Always returns true.
-
- lcm
Returns the least common multiple (always positive).
-
- next
Returns the Integer equal to int + 1.
-
- numerator
Returns self.
-
- odd?
Returns true if int is an odd number.
-
- ord
Returns the int itself.
-
- pred
Returns the Integer equal to int - 1.
-
- rationalize
Returns the value as a rational.
-
- round
Rounds flt to a given precision in decimal digits (default 0 digits).
-
- succ
Returns the Integer equal to int + 1.
-
- times
Iterates block int times, passing in values from zero to int - 1.
-
- to_i
As int is already an Integer, all these methods simply return the receiver.
-
- to_int
As int is already an Integer, all these methods simply return the receiver.
-
- to_r
Returns the value as a rational.
-
- truncate
As int is already an Integer, all these methods simply return the receiver.
-
- upto
Iterates block, passing in integer values from int up to and including limit.
Methods included from Precision
included, #prec, #prec_f, #prec_i
Methods inherited from Numeric
#%, #+@, #-@, #, #abs, #abs2, #angle, #arg, #class, #coerce, #conj, #conjugate, #div, #divmod, #dup, #eql?, #fdiv, #i, #imag, #imaginary, #initialize_copy, #magnitude, #modulo, #nonzero?, #phase, #polar, #quo, #real, #real?, #rect, #rectangular, #remainder, #scalar?, #singleton_method_added, #step, #to_c, #zero?
Methods included from Comparable
Methods inherited from NSNumber
#boolValue, #charValue, #compare:, #decimalValue, #descriptionWithLocale:, #doubleValue, #floatValue, #initWithBool:, #initWithChar:, #initWithDouble:, #initWithFloat:, #initWithInt:, #initWithInteger:, #initWithLong:, #initWithLongLong:, #initWithShort:, #initWithUnsignedChar:, #initWithUnsignedInt:, #initWithUnsignedInteger:, #initWithUnsignedLong:, #initWithUnsignedLongLong:, #initWithUnsignedShort:, #intValue, #integerValue, #isEqualToNumber:, #longLongValue, #longValue, numberWithBool:, numberWithChar:, numberWithDouble:, numberWithFloat:, numberWithInt:, numberWithInteger:, numberWithLong:, numberWithLongLong:, numberWithShort:, numberWithUnsignedChar:, numberWithUnsignedInt:, numberWithUnsignedInteger:, numberWithUnsignedLong:, numberWithUnsignedLongLong:, numberWithUnsignedShort:, #objCType, #shortValue, #stringValue, #unsignedCharValue, #unsignedIntValue, #unsignedIntegerValue, #unsignedLongLongValue, #unsignedLongValue, #unsignedShortValue
Methods inherited from NSValue
#getValue:, #initWithBytes:objCType:, #isEqualToValue:, #nonretainedObjectValue, #objCType, #pointerValue, #rangeValue, value:withObjCType:, valueWithBytes:objCType:, valueWithNonretainedObject:, valueWithPointer:, valueWithRange:
Methods inherited from NSObject
#!, #!=, #!~, #, #==, #===, #=~, #Rational, #__callee__, #__method__, #__send__, #__type__, `, alloc, allocWithZone:, #autoContentAccessingProxy, autoload, autoload?, autorelease_pool, #awakeAfterUsingCoder:, binding, block_given?, caller, cancelPreviousPerformRequestsWithTarget:, cancelPreviousPerformRequestsWithTarget:selector:object:, catch, class, classFallbacksForKeyedArchiver, #classForCoder, #classForKeyedArchiver, classForKeyedUnarchiver, #clone, conformsToProtocol:, #copy, copyWithZone:, #dealloc, #define_singleton_method, description, display, #doesNotRecognizeSelector:, #dup, #enum_for, #eql?, #equal?, #extend, fail, #finalize, format, #forwardInvocation:, #forwardingTargetForSelector:, framework, #freeze, #frozen?, getpass, gets, global_variables, #init, initialize, #initialize_clone, #initialize_copy, #initialize_dup, #inspect, instanceMethodForSelector:, instanceMethodSignatureForSelector:, #instance_eval, #instance_exec, #instance_of?, #instance_variable_defined?, #instance_variable_get, #instance_variable_set, #instance_variables, instancesRespondToSelector:, isSubclassOfClass:, #is_a?, iterator?, #kind_of?, lambda, load, load_bridge_support_file, load_plist, local_variables, loop, #method, #methodForSelector:, #methodSignatureForSelector:, #methods, #mutableCopy, mutableCopyWithZone:, new, #nil?, open, p, #performSelector:onThread:withObject:waitUntilDone:, #performSelector:onThread:withObject:waitUntilDone:modes:, #performSelector:withObject:afterDelay:, #performSelector:withObject:afterDelay:inModes:, #performSelectorInBackground:withObject:, #performSelectorOnMainThread:withObject:waitUntilDone:, #performSelectorOnMainThread:withObject:waitUntilDone:modes:, print, printf, #private_methods, proc, #protected_methods, #public_method, #public_methods, #public_send, putc, puts, raise, rand, readline, readlines, #replacementObjectForCoder:, #replacementObjectForKeyedArchiver:, require, resolveClassMethod:, resolveInstanceMethod:, #respond_to?, #respond_to_missing?, select, #send, setVersion:, #singleton_methods, sprintf, srand, superclass, #taint, #tainted?, #tap, test, throw, #to_plist, #to_s, trace_var, trap, #trust, #untaint, untrace_var, #untrust, #untrusted?, version
Constructor Details
This class inherits a constructor from NSObject
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class NSObject
Instance Method Details
- (Integer) to_i - (Integer) to_int - (Integer) floor - (Integer) ceil - (Integer) truncate
As int is already an Integer, all these methods simply return the receiver.
- (String) chr([encoding])
Returns a string containing the character represented by the receiver's value according to encoding.
65.chr #=> "A"
230.chr #=> "\346"
255.chr(Encoding::UTF_8) #=> "\303\277"
- (1) denominator
Returns 1.
- (self) downto(limit) {|i| ... } - (Enumerator) downto(limit)
Iterates block, passing decreasing values from int down to and including limit.
If no block is given, an enumerator is returned instead.
5.downto(1) { |n| print n, ".. " }
print " Liftoff!\n"
produces:
5.. 4.. 3.. 2.. 1.. Liftoff!
- (Boolean) even?
Returns true if int is an even number.
- (Integer) to_i - (Integer) to_int - (Integer) floor - (Integer) ceil - (Integer) truncate
As int is already an Integer, all these methods simply return the receiver.
- (Integer) gcd(int2)
Returns the greatest common divisor (always positive). 0.gcd(x) and x.gcd(0) return abs(x).
For example:
2.gcd(2) #=> 2
3.gcd(-7) #=> 1
((1<<31)-1).gcd((1<<61)-1) #=> 1
- (Array) gcdlcm(int2)
Returns an array; [int.gcd(int2), int.lcm(int2)].
For example:
2.gcdlcm(2) #=> [2, 2]
3.gcdlcm(-7) #=> [1, 21]
((1<<31)-1).gcdlcm((1<<61)-1) #=> [1, 4951760154835678088235319297]
- (true) integer?
Always returns true.
- (Integer) lcm(int2)
Returns the least common multiple (always positive). 0.lcm(x) and x.lcm(0) return zero.
For example:
2.lcm(2) #=> 2
3.lcm(-7) #=> 21
((1<<31)-1).lcm((1<<61)-1) #=> 4951760154835678088235319297
- (Integer) next - (Integer) succ
Returns the Integer equal to int + 1.
1.next #=> 2
(-1).next #=> 0
- (self) numerator
Returns self.
- (Boolean) odd?
Returns true if int is an odd number.
- (self) ord
Returns the int itself.
?a.ord #=> 97
This method is intended for compatibility to character constant in Ruby 1.9. For example, ?a.ord returns 97 both in 1.8 and 1.9.
- (Rational) rationalize([eps])
Returns the value as a rational. An optional argument eps is always ignored.
- (Integer, Float) round([ndigits])
Rounds flt to a given precision in decimal digits (default 0 digits). Precision may be negative. Returns a floating point number when ndigits is positive, self for zero, and round down for negative.
1.round #=> 1
1.round(2) #=> 1.0
15.round(-1) #=> 20
- (Integer) next - (Integer) succ
Returns the Integer equal to int + 1.
1.next #=> 2
(-1).next #=> 0
- (self) times {|i| ... } - (Enumerator) times
Iterates block int times, passing in values from zero to int - 1.
If no block is given, an enumerator is returned instead.
5.times do |i|
print i, " "
end
produces:
0 1 2 3 4
- (Integer) to_i - (Integer) to_int - (Integer) floor - (Integer) ceil - (Integer) truncate
As int is already an Integer, all these methods simply return the receiver.
- (Integer) to_i - (Integer) to_int - (Integer) floor - (Integer) ceil - (Integer) truncate
As int is already an Integer, all these methods simply return the receiver.
- (Rational) to_r
Returns the value as a rational.
For example:
1.to_r #=> (1/1)
(1<<64).to_r #=> (18446744073709551616/1)
- (Integer) to_i - (Integer) to_int - (Integer) floor - (Integer) ceil - (Integer) truncate
As int is already an Integer, all these methods simply return the receiver.
- (self) upto(limit) {|i| ... } - (Enumerator) upto(limit)
Iterates block, passing in integer values from int up to and including limit.
If no block is given, an enumerator is returned instead.
5.upto(10) { |i| print i, " " }
produces:
5 6 7 8 9 10