-1

Input:

 array = ['A', 'B', 'C']

Desired output:

'A', 'B', 'C'

I'm using legato gem to chain google analytics filters. My method call looks like this:

response = KeywordRevenueData.results(profile, self.options).for_keywords(array)

I thought this would work,

array.map(&:inspect).join(", ")

but for some reason it doesn't.

EDIT: It works fine when I put the literal strings in the method call:

response = KeywordRevenueData.results(profile, self.options).for_keywords("A", "B", "C")

single or double quotes seem to work fine if they are literals in the method call

mnort9
  • 1,810
  • 3
  • 30
  • 54

2 Answers2

1

You could use :

array.map{|l| "'" + l + "'"}.join(", ")

if you need to force the presence of surrounding quotes

This answer also has interesting suggestions :

Community
  • 1
  • 1
thibaultP
  • 116
  • 4
1

Use * to pass array elements as arguments:

response = KeywordRevenueData.results(profile, self.options).for_keywords(*array)  # Note the *
Sergey Bolgov
  • 806
  • 5
  • 6