Class: Integer

Inherits:
Object
  • Object
show all
Defined in:
lib/bases/monkeypatches/integer.rb

Overview

Some monkeypatches to the Integer class.

Instance Method Summary collapse

Instance Method Details

#to_base(base, opts = {}) ⇒ String

Convert this number to a given base.

Parameters:

  • new_base (Integer|Array)

    The same as in in_base

  • opts (Hash) (defaults to: {})

    A small hash of options

Returns:

See Also:



9
10
11
# File 'lib/bases/monkeypatches/integer.rb', line 9

def to_base(base, opts = {})
  Bases.val(self).to_base(base, opts)
end

#to_binaryString

Convert this number in binary form.

Returns:

See Also:



16
17
18
# File 'lib/bases/monkeypatches/integer.rb', line 16

def to_binary
  to_base(2)
end

#to_hexString

Convert this number in hexadecimal form.

Returns:

See Also:



23
24
25
# File 'lib/bases/monkeypatches/integer.rb', line 23

def to_hex
  to_base(16)
end