Pasta
Pasta

Reputation: 1790

How to ignore all the quotes and double quotes in a String in Ruby?

i would like to mock a web service response. The response is a XML, and contains both simple quotes and double quotes.

The response is pretty big, so here are my solutions:

But the thing is, I'd like to test a large response, and not create a resource test folder with a file. And as you can imagine, backslashing everything is long and boring.

I also tried the triple double quote, not working of course.

How would you do it?

Upvotes: 1

Views: 258

Answers (3)

Jed Schneider
Jed Schneider

Reputation: 14671

use the %Q operator

a = :jed

%Q| "these double quotes are ignored" for as
    long as you can type says #{a}
  |

any start end delimiters work so if you are using tables in cucumber for example you can use backticks instead of pipes

Upvotes: 3

noodl
noodl

Reputation: 17408

→ irb
ruby-1.9.2-p0 > str = <<-STR
ruby-1.9.2-p0"> ' single quote
ruby-1.9.2-p0"> " double quote
ruby-1.9.2-p0"> STR
 => "' single quote\n" double quote\n" 
ruby-1.9.2-p0 > 

Upvotes: 0

Jonas Elfstr&#246;m
Jonas Elfstr&#246;m

Reputation: 31438

You could use Ruby here documents.

xml = <<DOC
<xml>
<food attribute="soup">'eel'</food>
</xml>
DOC

Upvotes: 4

Related Questions