Class: Integer
- Defined in:
- lib/sixarm_ruby_ramp/integer.rb,
lib/sixarm_ruby_ramp/integer/rbit.rb
Overview
Integer extensions
Instance Method Summary collapse
-
#maps ⇒ Object
Syntactic sugar to yield n times to a block.
-
#rbit(count = 8) ⇒ Object
Reverse bit.
Instance Method Details
#maps ⇒ Object
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.
25 26 27 |
# File 'lib/sixarm_ruby_ramp/integer.rb', line 25 def maps return (0...self).map{|item| yield item} end |
#rbit(count = 8) ⇒ Object
Reverse bit.
Example:
0.rbit #=> 0
1.rbit #=> 128
2.rbit #=> 64
The bit count defaults to 8.
17 18 19 20 21 22 23 |
# File 'lib/sixarm_ruby_ramp/integer/rbit.rb', line 17 def rbit(count=8) z = self & 0 count.times{|i| z = z * 2 + self[i] } z end |