Module: Elixir::Integer
- Defined in:
- lib/elixir/integer.rb
Class Method Summary collapse
- .is_even(integer) ⇒ Object
- .is_odd(integer) ⇒ Object
- .parse(string) ⇒ Object
- .to_char_list(integer, base = 10) ⇒ Object
- .to_string(integer, base = 10) ⇒ Object
Class Method Details
.is_even(integer) ⇒ Object
5 6 7 |
# File 'lib/elixir/integer.rb', line 5 def is_even integer integer.even? end |
.is_odd(integer) ⇒ Object
9 10 11 |
# File 'lib/elixir/integer.rb', line 9 def is_odd integer integer.odd? end |
.parse(string) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/elixir/integer.rb', line 13 def parse string return :error unless string =~ /\A\d/ if remainder_index = string =~ /\D/ [Integer(string[0...remainder_index]), string[remainder_index..-1]] else [Integer(string), ''] end end |
.to_char_list(integer, base = 10) ⇒ Object
23 24 25 |
# File 'lib/elixir/integer.rb', line 23 def to_char_list integer, base = 10 integer.to_s(base).upcase.chars end |
.to_string(integer, base = 10) ⇒ Object
27 28 29 |
# File 'lib/elixir/integer.rb', line 27 def to_string integer, base = 10 integer.to_s(base).upcase end |