Rails - a variable as part of a method name

Possible duplicate:
Calling a function from a string with the function name in Ruby

I want to do something like this:

def self.greater_than(col_str='events') self."#{col_str}"_greater_than(30) # search logic scope method end 

How can I make it call correctly? I guess the syntax is probably similar to creating a dynamic method.

+4
source share
2 answers

You can try using send

 send("#{col_str}_greater_than".to_sym, 30) 
+12
source

try it

 def self.greater_than(col_str='events') self.send("#{col_str}_greater_than", 30) # search logic scope method end 
0
source

All Articles