加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 20:34:30 所属栏目:百科 来源:网络整理
导读:syntax error,unexpected $end,expecting keyword_end 我们都去过了!假设足够的代码改变了,快速浏览git diff或类似的内容并不明显,是否有一种简单的方法来找到缺少的结尾(缺少切换到基于缩进的语言,如Python)? FWIW,我使用Sublime Text 2作为我的编辑器.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读