Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/dust/helper.rb
Instance Method Summary collapse
- #is_a_defined_class? ⇒ Boolean
-
#is_int? ⇒ Boolean
checks if string is a valid integer.
-
#to_class ⇒ Object
stole this from Afz902k who posted something similar at stackoverflow.com adds ability to check if a class with the name of a string exists.
Instance Method Details
#is_a_defined_class? ⇒ Boolean
64 65 66 67 68 |
# File 'lib/dust/helper.rb', line 64 def is_a_defined_class? true if self.to_class rescue NameError false end |
#is_int? ⇒ Boolean
checks if string is a valid integer
71 72 73 |
# File 'lib/dust/helper.rb', line 71 def is_int? true if Integer(self) rescue false end |
#to_class ⇒ Object
stole this from Afz902k who posted something similar at stackoverflow.com adds ability to check if a class with the name of a string exists
58 59 60 61 62 |
# File 'lib/dust/helper.rb', line 58 def to_class Kernel.const_get self.capitalize rescue NameError nil end |