Project1
标题:
%s在一段代码中的含义
[打印本页]
作者:
fox1313304
时间:
2015-1-28 17:33
标题:
%s在一段代码中的含义
def debug(arr)
puts '一一一一一一一一一'
puts arr
end
h = [1,2,3,4,5]
h1 = h
h1.each{|v|puts sprintf('values is:%s',v)}
h2 = h.collect{|x| [x,x*2]}
debug h2
h3 = h.map{|x| x*3 }
debug h3
h4 = h.inject{|sum,item| sum+item}
debug h4
复制代码
百度了一下%s
%s
用于表示symbol, 但是不会对其中表达式等内容进行转化
代码如下:
>> %s(foo)
=> :foo
>> %s(foo bar)
=> :"foo bar"
>> %s(#{foo} bar)
=> :"\#{foo} bar"
复制代码
所以我想问在第一段代码里%s是什么意思 为什么输出的是序号呢
作者:
fox1313304
时间:
2015-1-28 17:34
是不是也有‘占位符’的感觉呢
作者:
喵呜喵5
时间:
2015-1-28 18:08
请参考F1附录部分sprintf格式字符串的内容
欢迎光临 Project1 (https://rpg.blue/)
Powered by Discuz! X3.1