In the context of Ruby symbols, what does "taguri" mean?
One of my colleagues and I were trying to understand why symbols are not automatically stringified when performing a regexp match on them:
>> :this =~ /./
=> false
>> :this =~ :this
=> false
>> :this =~ /:this/
=> false
One theory was that Symbol overrides the :=~ method so we checked out :this.methods. We found that Symbol does not override :=~ (1), but also noticed a very odd method:
>> :this.respond_to? :taguri=
=> true
In Japanese, たぐり (taguri) means "reeling in (thread, etc.)" (2), but I can't for the life of me figure out what that has to do with a symbol, an开发者_运维百科d I can't find Ruby source for the method in the Symbol class.
Any clues?
It's not "taguri" but is "Tag URI". Looking at the source code it all seems to deal with YAML and if you look in the YAML docs you see: http://ruby-doc.org/ruby-1.9/classes/YAML.html
And here's the absolute proof from 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
#
精彩评论