Mike Chaliy Mike Chaliy - 9 months ago 42
Ruby Question

Compare number and its string representation

val1 = 1
val2 = "1"

if val1 == val2 #< Question is in this line

How to compare number and its string representation?


Convert either to the other, so either:

val1.to_s == val2 # returns true


val1 == val2.to_i # returns true

Although ruby is dynamically typed (the type is known at runtime), it is also strongly typed (the type doesn't get implicitly typecast)