Gets undefined method error when calling parse method?

irb(main):001:0>  Time.parse("16:30")
NoMethodError: undefined method `parse' for Time:Class

Also rfc2822(), httpdate() and xmlschema(date) raises this error.


Solution: require the time.rb:
require 'time'

This is not a bug. It's because they are not core (But Time class is). Some implementation may auto require for you. But if you get this error, just try to require it.

Reference 12



==Traditional Chinese version==

呼叫Time.parse時得到undefined method錯誤?

irb(main):001:0>  Time.parse("16:30")
NoMethodError: undefined method `parse' for Time:Class

rfc2822(), httpdate() and xmlschema(date) 也會爆這個錯誤


解決方法: require time.rb:
require 'time'

這不是bug,這是因為這些methods不是core(但Time class本身是),有些implementation可能會自動幫你require,但如果你遇到這個error,就試試看require 'time'

參考來源 12

留言

這個網誌中的熱門文章

神之雫 的 雫 (雨下) 怎麼唸、意思是什麼

[已解決] 入肉 (肏) 的注音/怎麼唸?意思是什麼?(兒童不宜)

哆啦A夢放上任何東西都無違和感、彷彿有音效的滑鼠墊 這裡買得到