Take a look at method_missing, and specifically how ActiveRecord::Base
implements it in the Rails codebase.
method_missing is the method called when a method is..er...missing. :)
For example:
def method_missing(meth)
puts "Called #{meth}, which was missing..."
raise NoMethodError
end
Playing with that in a class should get you started.
--Jeremy
On Feb 6, 2008 5:29 PM, Luke Grimstrup
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
> How do you write a method thats similar to find_by_username, I want to
> write a method that works dynamically like that, but I have no idea
> where to begin...
>
> Do you declare the method differently? How do you access the part of the
> method header you want, i.e. username?
>
> TIA
> Luke
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--
http://www.jeremymcanally.com/
My books:
Ruby in Practice
http://www.manning.com/mcanally/
My free Ruby e-book
http://www.humblelittlerubybook.com/
My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.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
-~----------~----~----~----~------~----~------~--~---