---
title: "ruby 中的多行字符串(multiple lines of string) %Q, %w, %q "
author: "sg552"
date: "2012-07-31T10:01:38Z"
tags: []
categories: ["编程语言"]
slug: "ruby-multiple-lines-of-string-q-w-q"
draft: false
lastmod: "2012-07-31T10:01:38Z"
id: 1613139
url: "https://sg552.iteye.com/blog/1613139"
---

%Q 代表一个 双引号的字符串， 例如 
a = "foo"
a = %Q{ foo }

%q 代表单引号字符串， 不能使用 #{var}的形式。 例如：
b = 'bar 
bar'
b = %q{bar
bar}


```ruby
  
 CONST = "apple"
 abc = %q[ abc abc
 cde
 def
 this is a const: #{const}   
 ]
 puts abc

```

输出：

>  abc abc
> cde
> def
> this is a CONST: #{CONST}
> 


%q, %Q, %w 后面可以跟着：  {}, , ||
例如：
%Q 
%Q| hello |
都是一样的。