开发者

List of all Ruby "special quotes"

E.g.:

> %w{Maine Michigan California}
=> ["Maine", "Michigan", "California"]

> %{a b}
=> "a b"

Where can I find a list of all of these? (And what 开发者_Go百科are they called?)


I have heard them called percent methods before. They are mostly carry-overs from Perl. Here is a good list summarizing them


They're called literals! Check this table:

http://phrogz.net/programmingruby/language.html#table_18.1

EDIT:

As Karl points out in the comments, the whole chunk isn't actually a literal; the percent sign signals that a literal will follow, while the letter specifies the type of the literal. The opening brace (though one could also use, for example, “(”, “[”, “{”, or “<”) is a delimiter marking the beginning of a literal. From the link above:

the literal consists of the characters up to the matching closing delimiter, taking account of nested delimiter pairs. For all other delimiters, the literal comprises the characters up to the next occurrence of the delimiter character.

Hope that helps! Apologies for the first, sloppier answer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜