def [](tag) ....find_by_name(tag.to_s).......end

Given below is a model from mephisto blogging tool.

class Tag < ActiveRecord::Base
@@tag_parse_regex = /((?: |)[’"]{0,1})[’"]?\s*(.?)\s(?:[,’"]|$)(?:\1(?: |$))/
has_many :taggings

class << self
def
find_by_name(tag.to_s)
end


How to consume the above method and why it in this confusing way. Why the name of the method is [] …seems like an index to me. Am I supposed to consume this method Tag.[1] ?

Thanks.

Yes, this is how you define the square-bracket method in ruby. You do not need a "." to call it, like other methods:

Tag[:something]

Duane Johnson
(canadaduane)
http://blog.inquirylabs.com/

Thanks.