2011-02-03 28 views
2

之一,我試圖對他們進行正則表達式匹配時,瞭解爲什麼符號不會自動字符串化:在Ruby符號的情況下,「taguri」是什麼意思?我的同事

>> :this =~ /./ 
=> false 
>> :this =~ :this 
=> false 
>> :this =~ /:this/ 
=> false 

一種理論是,符號覆蓋:=〜方法,以便我們檢查了:這。方法。我們發現,符號不重寫:=〜(1),但也注意到一個很奇怪的方法:

>> :this.respond_to? :taguri= 
=> true 

在日本,たぐり(taguri)的意思是 「(線程等)繅絲」(2) ,但我不能爲了我的生活找出與符號有什麼關係,並且我無法在Symbol類中找到該方法的Ruby源代碼。

任何線索?

回答

5

這不是「taguri」而是「Tag URI」。查看源代碼,這一切似乎來處理YAML,如果你在YAML文檔看你看:http://ruby-doc.org/ruby-1.9/classes/YAML.html

下面是從tag.rb確鑿證據:

# Associates a taguri _tag_ with a Ruby class _cls_. The taguri is used to give types 
# to classes when loading YAML. Taguris are of the form: 
# 
# tag:authorityName,date:specific 
# 
# The +authorityName+ is a domain name or email address. The +date+ is the date the type 
# was issued in YYYY or YYYY-MM or YYYY-MM-DD format. The +specific+ is a name for 
# the type being added. 
# 
# For example, built-in YAML types have 'yaml.org' as the +authorityName+ and '2002' as the 
# +date+. The +specific+ is simply the name of the type: 
# 
# tag:yaml.org,2002:int 
# tag:yaml.org,2002:float 
# tag:yaml.org,2002:timestamp 
# 
# The domain must be owned by you on the +date+ declared. If you don't own any domains on the 
# date you declare the type, you can simply use an e-mail address. 
# 
# tag:[email protected],2004:notes/personal 
# 
+1

這是非常有趣的。你會認爲他們會像tag_uri一樣,像is_a ?, to_s等人一樣。 – 2011-02-03 14:07:08

相關問題