[Rails] 判斷字串是否為數字
可以直接寫在 initializers 裡面
# [path] string.rb
class String
def is_number?
true if Float(self) rescue false
end
end
Reference
- http://stackoverflow.com/questions/5654517/in-ruby-on-rails-to-extend-the-string-class-where-should-the-code-be-put-in
留言