微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

有没有快速的方法来找到Ruby中的缺少的结尾?

Syntax error,unexpected $end,expecting keyword_end

我们都去过了!假设足够的代码改变了,快速浏览git diff或类似的内容并不明显,是否有一种简单的方法来找到缺少的结尾(缺少切换到基于缩进的语言,如Python)?

FWIW,我使用Sublime Text 2作为我的编辑器.

解决方法

如果您使用的是Ruby 1.9,请在运行ruby程序时尝试使用-w标志.
# t.rb
class Example
  def meth1
    if Time.Now.hours > 12
      puts "Afternoon"
  end
  def meth2
    # ...
  end
end

ruby t.rb  
=> t.rb:10: Syntax error,expecting keyword_end

ruby -w t.rb
=> t.rb:5: warning: mismatched indentations at 'end' with 'if' at 3
   t.rb:9: warning: mismatched indentations at 'end' with 'def' at 2
   t.rb:10: Syntax error,expecting keyword_end

资源:

http://pragdave.blogs.pragprog.com/pragdave/2008/12/ruby-19-can-check-your-indentation.html

原文地址:https://www.jb51.cc/ruby/273690.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐