有没有一种简单的方法在Rails中将以下逻辑应用于字符串?
当然,有人可能会这样做:
if string does NOT end with '.' then add '.'
if string does NOT begin with 'http://' then add 'http://'.
当然,有人可能会这样做:
string[0..6] == 'http://' ? nil : (string = 'http://' + string)
但是这种方法有点笨拙,无法识别 https://
。有没有更好的Rails方式来处理这个问题?