Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/rackjson/extensions/core/string.rb

Instance Method Summary collapse

Instance Method Details

#numeric?Boolean

Returns:

  • (Boolean)


2
3
4
# File 'lib/rackjson/extensions/core/string.rb', line 2

def numeric?
  true if Float(self) rescue false
end

#to_numberObject



6
7
8
9
10
11
12
# File 'lib/rackjson/extensions/core/string.rb', line 6

def to_number
  if numeric?
    f = to_f
    i = to_i
    f == i ? i : f
  end
end