0

I'm just starting to use Sequel in Ruby, and like it alot.

I want to pass a variable to the "from" method. So instead of calling a method like so:

DB.from(:items)

I'd like to call the method with a variable. For example:

# both of the following approaches fail
tableName = "items"
DB.from(tableName)
DB.from(:tableName)

But it fails with a sql error about a value that's not in my variable. I don't think this is a Sequel issue... I think it's a "I'm new to Ruby" issue.

How can I pass a variable to the from method above?

Brad Parks
  • 66,836
  • 64
  • 257
  • 336

1 Answers1

3

Do as below using String#to_sym method :

DB.from(tableName.to_sym)

Looking at the documentation of Sequel::Database#from, it seems it accepts all arguments as symbols. Thus you need to convert the string object pointed by the local variable tableName, to a symbol object.

Arup Rakshit
  • 116,827
  • 30
  • 260
  • 317
  • thanks! i read those docs but i didn't get that from it.... i tried the "to_sym" method and it worked great... – Brad Parks Feb 20 '14 at 00:36