class Integer
Integer
extensions
Public Instance Methods
maps() { |item| ... }
click to toggle source
Syntactic sugar to yield n times to a block.
## Comparison to Integer#times
Integer#maps
is similar to Integer#times except that the output from each call to the block is captured in an array element and that array is returned to the calling code.
@return an array of results
@example Generate an array of three random numbers
3.maps{rand} => [0.0248131784304143, 0.814666170190905, 0.15812816258206]
@example Multiply the current index
3.maps{|i| i * 2} => [0, 2, 4]
# File lib/sixarm_ruby_ramp/integer.rb, line 24 def maps return (0...self).map{|item| yield item} end
rbit(count=8)
click to toggle source
Reverse bit.
Example:
0.rbit #=> 0 1.rbit #=> 128 2.rbit #=> 64
The bit count defaults to 8.
@param count [Integer] the count of bits to reverse
# File lib/sixarm_ruby_ramp/integer/rbit.rb, line 16 def rbit(count=8) z = self & 0 count.times{|i| z = z * 2 + self[i] } z end