我正在制作一个Ruby宝石,我想在文件中添加注释。这是允许的,还是会把宝石弄砸?我的代码:
# 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
提前谢谢。
我正在制作一个Ruby宝石,我想在文件中添加注释。这是允许的,还是会把宝石弄砸?
与大多数编程语言一样,Ruby也有注释。事实上,Ruby有两种评论:
-
单行注释以标记
#
开始,以行的末尾结束:#!/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
-
多行注释在一行的开头以标记
=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信息技术——程序设计语言——Ruby规范,第8.5节注释
- Ruby Spec Suite的
language/comment_spec.rb
,又名ruby/spec
- David Flanagan和Yukihiro‘matz’Matsumoto的Ruby编程语言的词汇结构
- Ruby文档的Ruby语法部分中的代码注释小节
- Dave Thomas、Andy Hunt和Chad Fowler的编程Ruby的介绍部分
.gemspec
和Gemfile
实际上只是普通的旧Ruby文件,与任何其他Ruby代码中应用的语法规则相同。与其他更详细的语言(咳嗽Java(不同,Ruby实际上非常适合编写配置,而且您通常不会发现它被用来代替XML、JSON或YAML文件。
他们只是没有.rb
的扩展-至于为什么这可能是一个只有原始作者才能回答的问题。同样现象的另一个例子是Rack的config.ru
。