とシャベル演算子を理解しようとすると:100ファイル私はkoans/about_strings.rbで<a href="http://rubykoans.com/" rel="nofollow noreferrer">http://rubykoans.com/</a></p> <p>を通じてつもりだ文字列
def test_the_shovel_operator_modifies_the_original_string
original_string = "Hello, "
hi = original_string
there = "World"
hi << there
assert_equal "Hello, World", original_string
# THINK ABOUT IT:
#
# Ruby programmers tend to favor the shovel operator (<<) over the
# plus equals operator (+=) when building up strings. Why?
end
私はoriginal_stringが等しいと思うだろうが、これは、合格「こんにちは」とHIは「こんにちは、世界」
に等しくなることを私はこのポスターは、同様の質問を持っていた見た、しかしかなり:
Why is the shovel operator (<<) preferred over plus-equals (+=) when building a string in Ruby?
何が欠けていますか?
? – Stefan
私は文字列を連結するために使用されるシャベル演算子を見たことがありません。もっと一般的なテクニックには、 "#{hi}#{there}}"や "[hi、there] .join'があります。再び3行で – moveson
ルック:3行目にあなたは* * *それら同じをするために*ルビーを教えて!したがって、彼らは同じ*です。 –