4

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.

Community
  • 1
  • 1
keruilin
  • 15,808
  • 32
  • 106
  • 174

2 Answers2

13

You could try using send

send("#{col_str}_greater_than".to_sym, 30)
theIV
  • 24,904
  • 5
  • 52
  • 57
0

Try this

def self.greater_than(col_str='events')
  self.send("#{col_str}_greater_than", 30) # search logic scope method
end
Harish Shetty
  • 63,225
  • 21
  • 147
  • 197