How to create this array in Ruby?
来源:互联网 发布:小啰啰崩没哏网络直播 编辑:程序博客网 时间:2024/05/21 11:20
I there a smarter way to define an array like this in Ruby?
array = [5, 15, 25, 35, 45, 55, 65, 75]
Thanks for any help.
Use Range#step
:
Range.new(5, 75).step(10).to_a# => [5, 15, 25, 35, 45, 55, 65, 75][*Range.new(5, 75).step(10)]# => [5, 15, 25, 35, 45, 55, 65, 75][*(5..75).step(10)] # (5..75) == Range.new(5, 75)# => [5, 15, 25, 35, 45, 55, 65, 75]
5.step(75, 10).to_a #=> [5, 15, 25, 35, 45, 55, 65, 75]
0 0
- How to create this array in Ruby?
- How to gsub \ in ruby array?
- How to create Ruby array sort the same as in AngularJS, lowercase should stand infront of uppercase
- How to format strings in an array in ruby?
- How to create ArrayList (ArrayList from array (T[]) in Java
- How to add two multidimensional array in ruby
- how to sort array in ruby if i have nil object inside array?
- [Ruby]How to create singleton class ?
- how to remove nil and blank string in an array in Ruby
- How to sort an array in Ruby to a particular order?
- ruby create 1 dimensional array to 2 dimensional array
- How to find number of a specific integer in an array of Fixnums ruby
- how to merge array of hash based same keys in ruby?
- How to get array from string contained identical symbols in Ruby?
- How to get array from string contained identical symbols in Ruby?
- How to create function polymorphism in C
- How to Create Procedure in DB2
- How To Create Alternate Background In WPF?
- java开发规范
- 关于sed命令的打印总结
- 数组-10. 求整数序列中出现次数最多的数(15)
- 让3D Plot类型的图片旋转起来...(Mathematica)
- eclipse常用快捷键
- How to create this array in Ruby?
- java_ssh_架包缺失异常总结
- Java synchronized详解
- 故乡的河
- java中的lang类型
- JD 1172:哈夫曼树
- NGUI小地图制作教程 1
- python基础教程_学习笔记10:异常
- c++习题1_H_虚函数-计算图形面积