What does %{} do in Ruby?

None of the other answers actually answer the question.

This is percent sign notation. The percent sign indicates that the next character is a literal delimiter, and you can use any (non alphanumeric) one you want. For example:

%{stuff}
%[stuff]
%?stuff?

etc. This allows you to put double quotes, single quotes etc into the string without escaping:

%{foo='bar with embedded "baz"'}

returns the literal string:
foo=’bar with embedded “baz”‘

The percent sign can be followed by a letter modifier to determine how the string is interpolated. For example, %Q[ ] is an interpolated String, %q[ ] is a non-interpolated String, %i[ ] is a non-interpolated Array of Symbols etc. So for example:

 %i#potato tuna#

returns this array of Symbols:

[:potato, :tuna]

Details are here: Wikibooks

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)