可以在 .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
如果你想知道所有血淋淋的细节,我建议阅读:
- ISO/IEC 30170:2012 Information technology — Programming languages — Ruby specification,第 8.5 节 评论
language/comment_spec.rb
of The Ruby Spec Suite aka ruby/spec
- 第 2.1 节 The Ruby Programming Language by David Flanagan and Yukihiro 'matz' Matsumoto
的词法结构
- Code Comments sub-section in the Ruby Syntax section of the Ruby documentation
- Programming Ruby by Dave Thomas, Andy Hunt, and Chad Fowler
的介绍部分
.gemspec
和 Gemfile
实际上只是普通的旧 Ruby 文件,并且与任何其他 Ruby 代码中的语法规则相同。与其他更冗长的语言(咳咳 Java)不同,Ruby 实际上非常适合编写配置,您会经常发现它代替 XML、JSON 或 YAML 文件。
他们只是没有 .rb
扩展名 - 至于为什么,那可能是只有原作者才能回答的问题。同样现象的另一个例子是 Rack 的 config.ru
.
我正在制作 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
如果你想知道所有血淋淋的细节,我建议阅读:
- ISO/IEC 30170:2012 Information technology — Programming languages — Ruby specification,第 8.5 节 评论
language/comment_spec.rb
of The Ruby Spec Suite akaruby/spec
- 第 2.1 节 The Ruby Programming Language by David Flanagan and Yukihiro 'matz' Matsumoto 的词法结构
- Code Comments sub-section in the Ruby Syntax section of the Ruby documentation
- Programming Ruby by Dave Thomas, Andy Hunt, and Chad Fowler 的介绍部分
.gemspec
和 Gemfile
实际上只是普通的旧 Ruby 文件,并且与任何其他 Ruby 代码中的语法规则相同。与其他更冗长的语言(咳咳 Java)不同,Ruby 实际上非常适合编写配置,您会经常发现它代替 XML、JSON 或 YAML 文件。
他们只是没有 .rb
扩展名 - 至于为什么,那可能是只有原作者才能回答的问题。同样现象的另一个例子是 Rack 的 config.ru
.