Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/toylang/monkey_patching/string.rb

Instance Method Summary collapse

Instance Method Details

#numeric_string?Boolean

Returns:

  • (Boolean)


4
5
6
7
8
# File 'lib/toylang/monkey_patching/string.rb', line 4

def numeric_string?
  !Float(self).nil?
rescue StandardError
  false
end

#to_numericObject



10
11
12
13
14
15
16
17
18
# File 'lib/toylang/monkey_patching/string.rb', line 10

def to_numeric
  return unless numeric_string?

  if index('.')
    to_f
  else
    to_i
  end
end