Module: Numeric::NumericExtensions
- Included in:
- Numeric
- Defined in:
- lib/ruckus/extensions/numeric.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#cap(limit) ⇒ Object
This HAS TO BE in the library somewhere already, but: give a fixnum, cap it at some number (ie, max(x, y) -> x).
- #sx16 ⇒ Object
- #sx32 ⇒ Object
-
#sx8 ⇒ Object
sign extend.
- #to_l16 ⇒ Object
- #to_l32 ⇒ Object
- #to_l8 ⇒ Object
- #to_x ⇒ Object
Class Method Details
.included(klass) ⇒ Object
112 113 114 |
# File 'lib/ruckus/extensions/numeric.rb', line 112 def self.included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#cap(limit) ⇒ Object
This HAS TO BE in the library somewhere already, but: give a fixnum, cap it at some number (ie, max(x, y) -> x). 10.cap(9) => 9.
7 |
# File 'lib/ruckus/extensions/numeric.rb', line 7 def cap(limit); self > limit ? limit : self; end |
#sx16 ⇒ Object
25 |
# File 'lib/ruckus/extensions/numeric.rb', line 25 def sx16; ([self].pack "s").unpack("S").first; end |
#sx32 ⇒ Object
26 |
# File 'lib/ruckus/extensions/numeric.rb', line 26 def sx32; ([self].pack "l").unpack("L").first; end |
#sx8 ⇒ Object
sign extend
24 |
# File 'lib/ruckus/extensions/numeric.rb', line 24 def sx8; ([self].pack "c").unpack("C").first; end |
#to_l16 ⇒ Object
15 16 17 |
# File 'lib/ruckus/extensions/numeric.rb', line 15 def to_l16 [self].pack("v") end |
#to_l32 ⇒ Object
11 12 13 |
# File 'lib/ruckus/extensions/numeric.rb', line 11 def to_l32 [self].pack("L") end |
#to_l8 ⇒ Object
19 20 21 |
# File 'lib/ruckus/extensions/numeric.rb', line 19 def to_l8 (self&0xFF).chr end |
#to_x ⇒ Object
9 |
# File 'lib/ruckus/extensions/numeric.rb', line 9 def to_x; to_s(16).rjust(8, "0"); end |