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 [](tag) 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 1, 2007, at 10:07 AM, Neeraj Kumar wrote:> 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 [](tag) > 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/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks. On 1/1/07, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > On Jan 1, 2007, at 10:07 AM, Neeraj Kumar wrote: > > > 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 [](tag) > > 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/ > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---