puts <<MSG heredoc syntax with unindented end marker MSG MSG end # heredoc syntax with an # unindented end marker # MSG
def heredoc2 puts <<-MSG heredoc syntax with an indented end marker MSG end # heredoc syntax with an # indented end marker
def heredoc3 puts <<~MSG heredoc syntax that strips whitespaces equal to the first line MSG end #heredoc syntax that strips #whitespaces equal to the # first line
<<~INTERPOLATED #{5} INTERPOLATED => "5\n"
<<~'UNINTERPOLATED' #{5} UNINTERPOLATED
| a = 5
# Percent literals %i[big 3d #{a} "] => [:big, :"3d", :"\#{a}", :"\""]
%I[big 3d #{a} "] => [:big, :"3d", :"5", :"\""]
%w[big 3d #{a} "] => ["big", "3d", "\#{a}", "\""]
%W[big 3d #{a} "] => ["big", "3d", "5", "\""]
%q(a "b" 'c' #{a}) => "a \"b\" 'c' \#{a}"
%Q(a "b" 'c' #{a}) => "a \"b\" 'c' 5"
%(a "b" 'c' #{a}) => "a \"b\" 'c' 5"
%s(mary's #{a} "twins") => :"mary's \#{a} \"twins\""
# Shell commands `echo hello world` => "hello world\n"
%x{echo hello world} => "hello world\n"
less_readable = `echo \`ls\`` => "main.rb Gemfile Gemfile.lock\n" more_readable = %x{echo `ls`} => "main.rb Gemfile Gemfile.lock\n"
|