On Mar 25, 10:07 pm, Larz <wbsurf...@gmail.com> wrote:
> ok,
>
> offhand I'm not sure how to create a method foo that is used like an
> array so I can say foo[:id], but I'll have to think about that or look
> through my books ...
>
There's not much to it:
class Foo
def initialize
@hash = {}
end
def [](key)
@hash[key]
end
def []=(key,value)
@hash[key]=value
end
end
That's not what's happening with params though. That's just a method
that returns a hash.
Fred
> On Mar 25, 5:46 pm, Frederick Cheung <frederick.che...@gmail.com>
> wrote:
>
> > On Mar 25, 8:57 pm, "wbsurf...@yahoo.com" <wbsurf...@gmail.com> wrote:
>
> > > I am curious how stuff like params and flash work in the controller ?
> > > Typically an instance variable is something like
> > > @params, or maybe self.params
>
> > @params is an instance variable, but self.params is a method called
> > params
>
> > > How does rails make params appear as if
> > > it's an instance variable ?
>
> > it doesn't. It just defines a method called params (and one called
> > flash etc...) on controllers. There use to be instance variables
> > called @params, @flash that you could use interchangeably but use of
> > those was deprecated and removed a while back.
>
> > Fred
--~--~---------~--~----~------------~-------~--~----~
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@googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---