Difference between '%{}', '%Q{}', '%q{}' in ruby string delimiters

后端 未结 2 1121
心在旅途
心在旅途 2020-12-15 03:44

I was going through an online tutorial on ruby and found this \"General Delimited Strings\",

%{a word}  # => \"a word\"
%Q{a word} # => \"a word\"
%q{         


        
2条回答
  •  遥遥无期
    2020-12-15 04:23

    %q(no interpolation)

    %Q(interpolation and backslashes)

    %(interpolation and backslashes)

    Example

    $ str = 'sushant'
    
    $ %q[#{str} "mane"]
     => "\#{str} \"mane\""
    
    $ %Q[#{str} "mane"]
     => "sushant \"mane\""
    
    $ %[#{str} "mane"]
     => "sushant \"mane\""
    

提交回复
热议问题