# Making those fancy advanced methods

**URL:** <https://www.ruby-forum.com/t/making-those-fancy-advanced-methods/128350>\
**Category:** Rails\
**Created:** [February 6, 2008, 11:29pm UTC](https://www.ruby-forum.com/t/making-those-fancy-advanced-methods/128350 "2008-02-06T23:29:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [February 6, 2008, 11:29pm UTC](https://www.ruby-forum.com/t/making-those-fancy-advanced-methods/128350/1 "2008-02-06T23:29:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [February 6, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/making-those-fancy-advanced-methods/128350/2 "2008-02-06T23:33:14Z")

</div>

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.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

–  
[http://www.jeremymcanally.com/](http://www.jeremymcanally.com/)

My books:  
Ruby in Practice

> **[Ruby in Practice](https://www.manning.com/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

> **[Site not found · DreamHost](http://www.humblelittlerubybook.com/)**
>
> The owner of this domain has not yet uploaded their website.

My blogs:

> **[Site not found · DreamHost](http://www.mrneighborly.com/)**
>
> The owner of this domain has not yet uploaded their website.

[http://www.rubyinpractice.com/](http://www.rubyinpractice.com/)
