I have a form in search rails that can receive a zip code or the name of a street, so I need to know what kind of variable the user is entering, if it is numbers, I do a zip search, I search the street name
I have a form in search rails that can receive a zip code or the name of a street, so I need to know what kind of variable the user is entering, if it is numbers, I do a zip search, I search the street name
It is possible to use Regular Expression , it checks according to character types or character patterns.
Ex:
[0-9] - Apenas numeros
[a-zA-Z] - Alfabeto com letras minusculas e maiusculas
Search for variations if you need to set specific patterns, it is very useful in certain scenarios.
To find out the type of the variable use the kind_of?
method, because it returns a Boolean value.
use this way:
variável.kind_of? tipo
Example to find out if "x" is integer type:
x.kind_of?Integer
irb(main):006:0> Integer = 1
(irb):6: warning: already initialized constant Integer
=> 1
irb(main):007:0> 1.class
=> Fixnum
This would be a way to find out the type of the variable.
Perhaps making a comparison using .class
I think .class
can help you by giving the information of the required variable, that's the only comparison!