galeal
February 6, 2008, 11:29pm
1
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
galeal
February 6, 2008, 11:33pm
2
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 G.
[email protected] wrote:
–
Posted via http://www.ruby-forum.com/ .
–
http://www.jeremymcanally.com/
My books:
Ruby in Practice
Like Ruby itself, Ruby in Practice will make you more productive. The book shows you practical techniques and strategies for small projects and large-scale environments. A cookbook-style reference, it gives you concrete examples of systems...
My free Ruby e-book
My blogs:
http://www.rubyinpractice.com/