And to continue with Jordan's theme, why not just extend your AR to include
such method?
class Something #assumes Something is an AR
def <<(item)
# do some pre processing...
# save tag to an AR association
end
end
but sure, much nicer in c++
On Thu, Apr 30, 2009 at 5:08 PM, Jordan Fowler <[email protected]> wrote:
> He Peter,
> The '<<' method is a special case because Ruby allows this to be called
> without a connecting '.' for message passing. Your syntax isn't valid
> because when the ruby interpreter comes across 'something<<' it assumes
> 'something' is the receiver. For example:
>
> class ArrayLike
> def <<(item)
> ...
> end
> end
>
> array_like = ArrayLike.new
>
> array_like << 'something' # valid
> array_like.<<('something') # valid
>
> -Jordan
>
>
> On Apr 30, 2009, at 2:01 PM, Peter Gumeson wrote:
>
>
> Hi gang,
>
> I am trying to define a method on an ActiveRecord model that simulates
> the push operator of an array (or enumerable). I was wondering if it's
> possible to do something similar to defining a setter, like this...
>
> def product_tags<<(tag)
> # do some pre processing...
> # save tag to an AR association
> end
>
> My guess is it needs to be implemented with an actual array. Anyone
> have any experience with this? Or do I just have a problem with my
> syntax?
>
> Thanks,
> Peter
>
>
>
>
>
> ---------------------------------------------------------------
>
> Jordan A. Fowler
> 2928 Fir St.
> San Diego, CA 92102
> E-mail: [email protected]
> Website: http://www.jordanfowler.com
> Phone: (619) 339-6752
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby
-~----------~----~----~----~------~----~------~--~---