Forum: Ruby on Rails def [](tag) ....find_by_name(tag.to_s).......end

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Raj S. (Guest)
on 2007-01-01 19:09
(Received via mailing list)
Given below is a model from mephisto blogging tool.

class Tag < ActiveRecord::Base
  @@tag_parse_regex = /((?:
  has_many :taggings

  class << self
    def [](tag)


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

Duane J. (Guest)
on 2007-01-02 01:58
(Received via mailing list)
On Jan 1, 2007, at 10:07 AM, Neeraj K. wrote:

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


Duane J.
Raj S. (Guest)
on 2007-01-02 05:00
(Received via mailing list)
This topic is locked and can not be replied to.