5

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
  • 16,782
  • 34
  • 108
  • 175

2 Answers2

13

You could try using send

send("#{col_str}_greater_than".to_sym, 30)
theIV
  • 25,434
  • 5
  • 54
  • 58
0

Try this

def self.greater_than(col_str='events')
  self.send("#{col_str}_greater_than", 30) # search logic scope method
end
Harish Shetty
  • 64,083
  • 21
  • 152
  • 198