我正在制作一個 Ruby 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 = '[email protected]' # 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
提前致謝。
uj5u.com熱心網友回復:
我正在制作一個 Ruby gem,我想在檔案中添加注釋。這是允許的,還是會弄亂寶石?
像大多數編程語言一樣,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 節注釋
language/comment_spec.rbRuby Spec Suite 又名ruby/spec- David Flanagan 和 Yukihiro 'matz' Matsumoto第 2.1 節Ruby 編程語言的詞法結構
- Ruby 檔案的Ruby 語法部分中的代碼注釋子部分
- Dave Thomas、Andy Hunt 和 Chad Fowler撰寫的Programming Ruby的介紹部分
uj5u.com熱心網友回復:
和實際上只是普通的舊 Ruby 檔案,并且適用與任何其他 Ruby 代碼相同的語法規則.gemspec。Gemfile與其他更冗長的語言(咳咳 Java)不同,Ruby 實際上非常適合撰寫配置,而且您經常會發現它沒有被用來代替 XML、JSON 或 YAML 檔案。
他們只是沒有.rb擴展名-至于為什么那可能是一個只有原始作者才能回答的問題。同樣現象的另一個例子是 Rack 的config.ru.
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/440718.html
上一篇:Ruby注入菊花鏈?
