Ruby范围作为序列
示例
范围最重要的用途是表达序列
语法:
(begin..end) => this construct will include end value (begin...end) => this construct will exclude end value
要么
Range.new(begin,end,exclude_end) => exclude_end is by default false
最重要的end值必须大于begin,否则将不返回任何值。
例子:
(10..1).to_a #=> []
(1...3) #=> [1, 2]
(-6..-1).to_a #=> [-6, -5, -4, -3, -2, -1]
('a'..'e').to_a #=> ["a", "b", "c", "d", "e"]
('a'...'e').to_a #=> ["a", "b", "c", "d"]
Range.new(1,3).to_a #=> [1, 2, 3]
Range.new(1,3,true).to_a#=> [1, 2]
热门推荐
2 祝福语简短的微信
10 关于水的简短祝福语
11 社团迎新祝福语简短英语
12 祝福语15字以内简短
13 晚来的生日祝福语简短
14 对新人祝福语大全简短
15 抗疫祝福语简短精辟
16 新婚宴祝福语简短大全
17 生日弟弟祝福语 简短独特
18 俄语随口祝福语简短版