Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在末尾添加点的Ruby映射_Ruby_String_Loops_String Concatenation - Fatal编程技术网

在末尾添加点的Ruby映射

在末尾添加点的Ruby映射,ruby,string,loops,string-concatenation,Ruby,String,Loops,String Concatenation,我有底线 new_records = records.map{|record| record.name.to_s.}.sort 哪个输出 # Current Output: new_records = ["ab-12.cd.net", "de-34.fg.net"] 我怎样才能让它在最后返回一个(点) # Desired Output: new_records = ["ab-12.cd.net.", "de-34.fg

我有底线

new_records = records.map{|record| record.name.to_s.}.sort
哪个输出

# Current Output:

new_records = ["ab-12.cd.net", "de-34.fg.net"]
我怎样才能让它在最后返回一个
(点)

# Desired Output:

new_records = ["ab-12.cd.net.", "de-34.fg.net."]
例如,我可以使用另一张地图

new_records = records.map{|record| record.name.to_s.}.sort
new_records2 = new_records.map { |record| "#{record}." }
但是,我们正在寻找一种有效的方法,使用第一张地图本身来实现它。

这将起作用:

new_records = records.map{|record| "#{record.name.to_s}." }.sort
您也可以这样使用
+

new_records = records.map{|record| record.name.to_s + "." }.sort

我建议您解释“和”之间的区别以及何时使用它们,因为您已经给出了两种类型的字符串连接的示例。@anothermh可以随意编辑答案并给出解释