Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails - variable as part of method name [duplicate]

Possible Duplicate:
Calling a Function From a String With the Function's 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 get this to call properly? I'm guessing the syntax is probably similar to creating a dynamic method.

like image 224
keruilin Avatar asked Dec 12 '22 08:12

keruilin


1 Answers

You could try using send

send("#{col_str}_greater_than".to_sym, 30)
like image 62
theIV Avatar answered Dec 27 '22 21:12

theIV