在Ruby符号的上下文中,“taguri”是什么意思?

时间:2011-02-03 08:57:36

标签: ruby

我和我的一位同事试图理解为什么在对它们执行正则表达式匹配时,符号不会自动进行字符串化:

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

有一种理论认为,Symbol会覆盖:=〜方法,所以我们检查了:this.methods。我们发现Symbol不会覆盖:=〜(1),但也注意到一种非常奇怪的方法:

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

在日语中,たぐり(taguri)的意思是“卷入(线程等)”(2),但我不能为我的生活找出与符号有什么关系,我找不到符号类中方法的Ruby源代码。

任何线索?

1 个答案:

答案 0 :(得分: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:why@ruby-lang.org,2004:notes/personal
#