Integers
64-bit signed integers with built-in methods for arithmetic, iteration, and type inspection.
Creating Integers
let x = 42
let negative = -100
let big = 9_000_000 # Underscores for readability
let typed: Int = 10
Arithmetic Methods
.pow(exponent)
Raises the integer to the given power.
2.pow(10) # 1024
3.pow(3) # 27
2.pow(-1) # 0.5 (returns float for negative exponents)
Predicate Methods
.even? / .odd?
Check if the integer is even or odd.
4.even? # true
4.odd? # false
7.even? # false
7.odd? # true
.positive? / .negative?
Check if the integer is positive or negative.
5.positive? # true
(-3).negative? # true
0.positive? # false
0.negative? # false
.between?(min, max)
Check if the integer is within the given range (inclusive).
5.between?(1, 10) # true
15.between?(1, 10) # false
.clamp(min, max)
Constrain the integer to be within the given range.
15.clamp(1, 10) # 10
(-5).clamp(0, 100) # 0
5.clamp(0, 100) # 5
Iteration Methods
.times |i| ... end
Execute a block n times, passing the index (0 to n-1).
3.times |i|
println(i)
end
# 0
# 1
# 2
.upto(limit) |i| ... end
Iterate from the integer up to the limit (inclusive).
1.upto(5) |i|
print(i + " ")
end
# 1 2 3 4 5
.downto(limit) |i| ... end
Iterate from the integer down to the limit (inclusive).
5.downto(1) |i|
print(i + " ")
end
# 5 4 3 2 1
Conversion Methods
Introspection Methods
.is_a?(type_name)
Check if the value is of the given type. Supports "int", "numeric", and "object".
42.is_a?("int") # true
42.is_a?("numeric") # true
42.is_a?("string") # false
.blank? / .present?
Integers are always present (never blank).
42.blank? # false
42.present? # true
0.blank? # false
0.present? # true