Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Concat double quotes with String in Ruby

I need a string with double quotes

tried

expectedValue = "/""+expectedValue+"/""

but did not worked -

Throws below error -

NoMethodError: undefined method `/' for "/+expectedValue+":String

Please suggest.

like image 712
Anand Chavan Avatar asked Jun 18 '14 13:06

Anand Chavan


People also ask

How do you add a double quote to a string in Ruby?

Answer 51d2afb1282ae33a990093c5. Single-quoted and double-quoted strings are (almost) equivalent in Ruby. Of course, you have to escape \' inside single-quoted strings and \" inside double-quoted strings.

How do you print double quotes in Ruby?

Alternate double quotesThe %Q operator (notice the case of Q in %Q ) allows you to create a string literal using double-quoting rules, but without using the double quote as a delimiter. It works much the same as the %q operator. Just like double quotes, you can interpolate Ruby code inside of these string literals.

How do you add to a string in Ruby?

You can use the + operator to append a string to another. In this case, a + b + c , creates a new string. Btw, you don't need to use variables to make this work.


1 Answers

Probably you mean:

expectedValue = "\""+expectedValue+"\""

or more in ruby style:

expectedValue = "\"#{expectedValue}\""
like image 188
zishe Avatar answered Sep 21 '22 23:09

zishe