可以在 .gemspec 文件中使用注释吗?

Can comments be used in the .gemspec file?

我正在制作 Ruby gem,我想在文件中添加注释。这会被允许,还是会弄乱 gem?我的代码:

# test

Gem::Specification.new do |s|
  s.name        = 'My Gem' # Add a better name
  s.version     = '0.0.0'
  s.summary     = "Summary of my gem"
  s.description = "More detailed description" # Maybe a tiny bit more detailed?
  s.authors     = ["Me"]
  s.email       = 'foo.bar@example.net' # Please don't email me, as I rarely look at my email
  s.files       = ["lib/myGem.ruby"] # Change to .rb
  s.homepage    =
    'https://rubygems.org/gems/foobar'
end

# Add s.license

=begin
foo
bar
=end

提前致谢。

I'm making a Ruby gem, and I want to put comments in the file. Would this be allowed, or would it mess up the gem?

像大多数编程语言一样,Ruby 有注释。其实Ruby有两种评论:

  • Single-line comments 以标记 # 开始,以行尾结束:
    #!/usr/bin/env ruby
    # Shebang lines are just interpreted as comments, which is clever.
    some_code # This is a comment.
    
    # So is this.
    
    foo.bar.
      # Comments are allowed in lots of places.
      baz(
        # And here.
        23, # And here.
        42,
        # And here.
        :foo
    )
    # Even here.
    .quux
    
  • Multi-line comments 以行首的标记 =begin 开始,以行首的标记 =end 结束一行:
    some_code
    =begin This is a comment.
    This is still the same comment.
    So is this.
    This is not the end of the comment: =end
    
    But this is:
    =end
    

如果你想知道所有血淋淋的细节,我建议阅读:

.gemspecGemfile 实际上只是普通的旧 Ruby 文件,并且与任何其他 Ruby 代码中的语法规则相同。与其他更冗长的语言(咳咳 Java)不同,Ruby 实际上非常适合编写配置,您会经常发现它代替 XML、JSON 或 YAML 文件。

他们只是没有 .rb 扩展名 - 至于为什么,那可能是只有原作者才能回答的问题。同样现象的另一个例子是 Rack 的 config.ru.