# Re: function names contain regex?

**URL:** <https://www.ruby-forum.com/t/re-function-names-contain-regex/55297>\
**Category:** Rails\
**Created:** [March 19, 2006, 7:30am UTC](https://www.ruby-forum.com/t/re-function-names-contain-regex/55297 "2006-03-19T07:30:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottrutherford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@scottrutherford](https://www.ruby-forum.com/u/scottrutherford)\
**Post date:** [March 19, 2006, 7:30am UTC](https://www.ruby-forum.com/t/re-function-names-contain-regex/55297/1 "2006-03-19T07:30:01Z")

</div>

> Is it possible to support something like the following:
> 
> def validate\_address{#/d/#)  
> x = {#1}  
> miscfunction(x)  
> end
> 
> And yes, I totally just made up some bogus syntax - I have no idea if a  
> variable function name containing a regular expression is possible…  
> perhaps through some trick of aliasing?

Perhaps what you want is method\_missing, which can intercept any  
message that doesn’t get caught by another method. For example:

class Dog  
def method\_missing id  
raise NoMethodError unless /say\_(\w+)\_(\d)\_times/ =~ id.id2name  
$2.to\_i.times do  
puts $1  
end  
end  
end

spot = Dog.new  
spot.say\_woof\_3\_times  
spot.say\_arf\_2\_times

Scott R.  
[http://scottraymond.net/](http://scottraymond.net/)

---

<div class="post-metadata">

**Author:** ![scottrutherford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@scottrutherford](https://www.ruby-forum.com/u/scottrutherford)\
**Post date:** [March 19, 2006, 12:17pm UTC](https://www.ruby-forum.com/t/re-function-names-contain-regex/55297/2 "2006-03-19T12:17:06Z")

</div>

> Perhaps what you want is method\_missing, which can intercept any  
> message that doesn’t get caught by another method. For example:

That’s really cool, Scott! I’ll add that to my recipe book.

So is that how find\_by\_name\_and\_password() functions are built?

Also, still curious if there’s a way for code in a controller function  
to  
find out it’s function name.

Thanks for that,  
Pete

---

<div class="post-metadata">

**Author:** ![scottrutherford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@scottrutherford](https://www.ruby-forum.com/u/scottrutherford)\
**Post date:** [March 19, 2006, 12:17pm UTC](https://www.ruby-forum.com/t/re-function-names-contain-regex/55297/3 "2006-03-19T12:17:09Z")

</div>

On Mar 18, 2006, at 11:39 PM, Pete F. wrote:

> > Perhaps what you want is method\_missing, which can intercept any  
> > message that doesn’t get caught by another method. For example:
> 
> That’s really cool, Scott! I’ll add that to my recipe book.
> 
> So is that how find\_by\_name\_and\_password() functions are built?
> 
> Also, still curious if there’s a way for code in a controller  
> function to find out it’s function name.

controller.action\_name

–  
– Tom M.
