有没有快速的方法来找到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

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...