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.
934f858e451cf9b771996b2940cd696b?d=identicon&s=25 Raj Singh (dorelal)
on 2007-01-01 18: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] ?

D8cb8c8cd40ddf0cd05241443a591868?d=identicon&s=25 Duane Johnson (Guest)
on 2007-01-02 00:58
(Received via mailing list)
On Jan 1, 2007, at 10:07 AM, Neeraj Kumar 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 Johnson
934f858e451cf9b771996b2940cd696b?d=identicon&s=25 Raj Singh (dorelal)
on 2007-01-02 04:00
(Received via mailing list)
This topic is locked and can not be replied to.