Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/core_ext/number.rb
Instance Method Summary collapse
Instance Method Details
#millis ⇒ Object
23 24 25 |
# File 'lib/core_ext/number.rb', line 23 def millis self / 1_000.0 end |
#to_bytes_ary(le: true, padding: 2) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/core_ext/number.rb', line 10 def to_bytes_ary(le: true, padding: 2) res = [] to_hex_str.chars.each_slice(2) { |byte| res << byte.join().to_i(16) } if res.size < padding res.prepend Array.new(padding - res.size) { 0 } res.flatten! end if le res.reverse! end res end |
#to_hex_str ⇒ Object
2 3 4 5 6 7 8 |
# File 'lib/core_ext/number.rb', line 2 def to_hex_str n = to_s(16).upcase if n.length.odd? n = "0#{n}" end n end |