2020-06-21 00:55:09 +03:00
|
|
|
class Integer
|
2020-06-27 20:07:47 +03:00
|
|
|
def abs
|
|
|
|
Primitive.attr! 'inline'
|
|
|
|
Primitive.cexpr! 'rb_int_abs(self)'
|
|
|
|
end
|
|
|
|
|
|
|
|
def bit_length
|
|
|
|
Primitive.attr! 'inline'
|
|
|
|
Primitive.cexpr! 'rb_int_bit_length(self)'
|
|
|
|
end
|
|
|
|
|
|
|
|
# call-seq:
|
|
|
|
# int.even? -> true or false
|
|
|
|
#
|
|
|
|
# Returns +true+ if +int+ is an even number.
|
|
|
|
def even?
|
|
|
|
Primitive.attr! 'inline'
|
2020-07-10 05:49:50 +03:00
|
|
|
Primitive.cexpr! 'rb_int_even_p(self)'
|
2020-06-27 20:07:47 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
# call-seq:
|
|
|
|
# int.integer? -> true
|
|
|
|
#
|
|
|
|
# Since +int+ is already an Integer, this always returns +true+.
|
|
|
|
def integer?
|
2020-07-02 03:44:23 +03:00
|
|
|
return true
|
2020-06-27 20:07:47 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def magnitude
|
|
|
|
Primitive.attr! 'inline'
|
|
|
|
Primitive.cexpr! 'rb_int_abs(self)'
|
|
|
|
end
|
|
|
|
|
|
|
|
# call-seq:
|
|
|
|
# int.odd? -> true or false
|
|
|
|
#
|
|
|
|
# Returns +true+ if +int+ is an odd number.
|
|
|
|
def odd?
|
|
|
|
Primitive.attr! 'inline'
|
|
|
|
Primitive.cexpr! 'rb_int_odd_p(self)'
|
|
|
|
end
|
|
|
|
|
|
|
|
# call-seq:
|
|
|
|
# int.ord -> self
|
|
|
|
#
|
|
|
|
# Returns the +int+ itself.
|
|
|
|
#
|
|
|
|
# 97.ord #=> 97
|
|
|
|
#
|
|
|
|
# This method is intended for compatibility to character literals
|
|
|
|
# in Ruby 1.9.
|
|
|
|
#
|
|
|
|
# For example, <code>?a.ord</code> returns 97 both in 1.8 and 1.9.
|
|
|
|
def ord
|
2020-07-02 03:44:23 +03:00
|
|
|
return self
|
2020-06-27 20:07:47 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
# call-seq:
|
|
|
|
# int.to_i -> integer
|
|
|
|
#
|
|
|
|
# Since +int+ is already an Integer, returns +self+.
|
|
|
|
#
|
|
|
|
# #to_int is an alias for #to_i.
|
|
|
|
def to_i
|
2020-07-02 03:44:23 +03:00
|
|
|
return self
|
2020-06-27 20:07:47 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
# call-seq:
|
|
|
|
# int.to_int -> integer
|
|
|
|
#
|
|
|
|
# Since +int+ is already an Integer, returns +self+.
|
|
|
|
def to_int
|
2020-07-02 03:44:23 +03:00
|
|
|
return self
|
2020-06-27 20:07:47 +03:00
|
|
|
end
|
|
|
|
|
2020-06-21 00:55:09 +03:00
|
|
|
# call-seq:
|
|
|
|
# int.zero? -> true or false
|
|
|
|
#
|
2020-06-30 11:13:37 +03:00
|
|
|
# Returns +true+ if +int+ has a zero value.
|
2020-06-21 00:55:09 +03:00
|
|
|
def zero?
|
2020-06-21 03:13:03 +03:00
|
|
|
Primitive.attr! 'inline'
|
2020-07-10 05:49:50 +03:00
|
|
|
Primitive.cexpr! 'rb_int_zero_p(self)'
|
2020-06-21 00:55:09 +03:00
|
|
|
end
|
|
|
|
end
|