提交 8040f527 编写于 作者: K kenta-s

Fix unexpected behavior of with $,

上级 b1a41701
......@@ -60,7 +60,7 @@ def to_sentence(array, options = {})
when 2
safe_join([array[0], array[1]], options[:two_words_connector])
else
safe_join([safe_join(array[0...-1], options[:words_connector]), options[:last_word_connector], array[-1]])
safe_join([safe_join(array[0...-1], options[:words_connector]), options[:last_word_connector], array[-1]], nil)
end
end
end
......
......@@ -87,4 +87,14 @@ def setup
assert_equal "one, two three", to_sentence(["one", "two", "three"], last_word_connector: " ")
assert_equal "one, two and three", to_sentence(["one", "two", "three"], last_word_connector: " and ")
end
test "to_sentence is not affected by $," do
$, = "|"
begin
assert_equal "one and two", to_sentence(["one", "two"])
assert_equal "one, two, and three", to_sentence(["one", "two", "three"])
ensure
$, = nil
end
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册