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.
==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’
喜歡這篇文章嗎?你可能也會喜歡我的學習電子報,我會分享經過篩選的優質內容 + 學習心得
📚 訂閱我的學習電子報
📖 涵蓋主題:
🧑💻 軟體工程
🎯 生產力
💰 商業理財
🧳 創業
🐱 奇怪的知識增加了
💭 思考人生心得
🎁 現在訂閱就送我個人非常愛用「學習任何領域皮毛的 AI Prompt」!
立即免費訂閱 →
✨ 不浪費你的時間,只分享達到我標準的優質內容