Class: Integer
- Defined in:
- ext/enterprise_script_service/mruby/src/numeric.c,
ext/enterprise_script_service/mruby/mrblib/numeric.rb
Overview
Integer
ISO 15.2.8
Instance Method Summary collapse
-
#ceil ⇒ Object
Returns the receiver simply.
-
#downto(num, &block) ⇒ Object
Calls the given block once for each Integer from
self
downtonum
. -
#floor ⇒ Object
(also: #round, #truncate)
Returns the receiver simply.
-
#next ⇒ Object
(also: #succ)
Returns self + 1.
-
#step(num = nil, step = 1, &block) ⇒ Object
Calls the given block from
self
tonum
incremented bystep
(default 1). -
#times(&block) ⇒ Object
Calls the given block
self
times. -
#upto(num, &block) ⇒ Object
Calls the given block once for each Integer from
self
uptonum
.
Instance Method Details
#ceil ⇒ Object
Returns the receiver simply.
ISO 15.2.8.3.14
133 134 135 |
# File 'ext/enterprise_script_service/mruby/mrblib/numeric.rb', line 133 def ceil self end |
#downto(num, &block) ⇒ Object
Calls the given block once for each Integer from self
downto num
.
ISO 15.2.8.3.15
47 48 49 50 51 52 53 54 55 56 |
# File 'ext/enterprise_script_service/mruby/mrblib/numeric.rb', line 47 def downto(num, &block) return to_enum(:downto, num) unless block i = self.to_i while i >= num block.call(i) i -= 1 end self end |
#floor ⇒ Object Also known as: round, truncate
Returns the receiver simply.
ISO 15.2.8.3.17
141 142 143 |
# File 'ext/enterprise_script_service/mruby/mrblib/numeric.rb', line 141 def floor self end |
#next ⇒ Object Also known as: succ
Returns self + 1
ISO 15.2.8.3.19
62 63 64 |
# File 'ext/enterprise_script_service/mruby/mrblib/numeric.rb', line 62 def next self + 1 end |
#step(num = nil, step = 1, &block) ⇒ Object
Calls the given block from self
to num
incremented by step
(default 1).
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'ext/enterprise_script_service/mruby/mrblib/numeric.rb', line 103 def step(num=nil, step=1, &block) raise ArgumentError, "step can't be 0" if step == 0 return to_enum(:step, num, step) unless block i = __coerce_step_counter(num, step) if num == self || step.infinite? block.call(i) if step > 0 && i <= (num||i) || step < 0 && i >= (num||-i) elsif num == nil while true block.call(i) i += step end elsif step > 0 while i <= num block.call(i) i += step end else while i >= num block.call(i) i += step end end self end |
#times(&block) ⇒ Object
Calls the given block self
times.
ISO 15.2.8.3.22
72 73 74 75 76 77 78 79 80 81 |
# File 'ext/enterprise_script_service/mruby/mrblib/numeric.rb', line 72 def times &block return to_enum :times unless block i = 0 while i < self block.call i i += 1 end self end |
#upto(num, &block) ⇒ Object
Calls the given block once for each Integer from self
upto num
.
ISO 15.2.8.3.27
88 89 90 91 92 93 94 95 96 97 |
# File 'ext/enterprise_script_service/mruby/mrblib/numeric.rb', line 88 def upto(num, &block) return to_enum(:upto, num) unless block i = self.to_i while i <= num block.call(i) i += 1 end self end |