2017-10-31 2 views

答えて

5

は、あなたが十分ではありません:)

%i[ ] # Non-interpolated Array of symbols, separated by whitespace 
%I[ ] # Interpolated Array of symbols, separated by whitespace 

私の検索から2番目のリンクはIRBでhttp://ruby.zigzo.com/2014/08/21/rubys-notation/

例の結果をググようです'および"

x = :test 

# %w won't interpolate #{...} style strings, leaving as literal 
%w[ #{x} x ] 
# => ["\#{x}", "x"] 

# %w will interpolate #{...} style strings, converting to string 
%W[ #{x} x ] 
# => [ "test", "x"] 

%i%Iと同じこと:

# %i won't interpolate #{...} style strings, leaving as literal, symbolized 
%i[ #{x} x ] 
# => [:"\#{x}", :x ] 

# %w will interpolate #{...} style strings, converting to symbols 
%I[ #{x} x ] 
# => [ :test, :x ] 
+0

別名[%表記](https://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Literals#The_.25_Notation) – anothermh

+0

これは正しいです。しかし、私は '%I'を使うのはお勧めしません。 –

0

それは%wようなものだと%W

関連する問題