Class: Object

Inherits:
BasicObject
Defined in:
lib/swak/toplevel.rb

Instance Method Summary collapse

Instance Method Details

#is_f?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/swak/toplevel.rb', line 33

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

#is_i?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/swak/toplevel.rb', line 29

def is_i?
  true if Integer(self) rescue false
end

#to_f_strictObject



46
47
48
49
50
51
52
# File 'lib/swak/toplevel.rb', line 46

def to_f_strict
  if is_f?
    return to_f
  else
    raise "String '#{self}' cannot be converted to a float"
  end
end

#to_i_strictObject



37
38
39
40
41
42
43
44
# File 'lib/swak/toplevel.rb', line 37

def to_i_strict
  if is_i?
    return to_i
  else
    raise "String '#{self}' cannot be converted to an int"
  end
    
end