2

错误 -

Inspecting 1 file
C

Offenses:

hellotk.rb:7:17: C: Do not use semicolons to terminate expressions.
  pack { padx 15; pady 15; side 'left'; }
                ^

1 file inspected, 1 offense detected

文件 -

#!/usr/bin/ruby
require 'tk'

root = TkRoot.new { title 'Hello, World!' }
TkLabel.new(root) do
  text 'Hello, World!'
  pack { padx 15; pady 15; side 'left'; }
end
TkButton.new do
  text 'Quit'
  command 'exit'
  pack('fill' => 'x')
end
Tk.mainloop

消除“;”的适当格式是什么 以便 rubocop 停止警告我我的文件写错了?我想以正确的方式消除这种冒犯。

4

1 回答 1

1

它希望您将表达式放在新行上,而不是用分号分隔它们

pack {
  padx 15
  pady 15
  side left
}

或者

pack do
  padx 15
  pady 15
  side left
end
于 2015-07-08T20:53:26.053 回答