1

If I have 3 named scopes like

class Foo

scope :test1, ...
scope :test2, ...
scope :test3, ...

And a function

def x(variable)

end

where variable is a string("test1","test2" or "test3")

How can I access the named scope just by knowing that variable's value ?

Something like Foo.variable

Erik Schierboom
  • 16,301
  • 10
  • 64
  • 81
vladCovaliov
  • 4,333
  • 2
  • 43
  • 58

1 Answers1

2

You would call Foo.public_send(variable).

sevenseacat
  • 24,699
  • 6
  • 63
  • 88