当前位置: 代码迷 >> Ruby/Rails >> ruby根本语法
  详细解决方案

ruby根本语法

热度:419   发布时间:2016-04-29 02:26:06.0
ruby基本语法

ruby语法手册;

http://ruby-china.org/topics/13622

http://ruby-doc.org

1.File.open("filename")

2.File.open("filename").readLines

3.array=[...]

4.array1 - array2

5.array.length array.size

6.array[(-)index]

7.array[f..t]

8.array[f...t]

9.array.delete_at(index)

10.array.slice!(f..t)

11.array.empty?

12.a.push(e)

13.a << e | a << [.....]

14.a.pop

15.a.shift

16.a.unshift(e)

17.a.methods

18.ARGV

19."".downcase

20.a.each do |e|

??????? ...

???? end

21.生成新Array

[1,2,3].collect do |e|  e*10end

?

[1,2,3].collect { |e| e * 10}

22. "....".split(reg)

23.a.include?(xxx)

24.

[1,2,3,4,5,6,7,8].reject {|e| e != 2}

25.装在文件 load 'xxx.rb'

26.__FILE__和$0是当前.rb文件名

27.a.any?

28.require和load的区别:require只加载一次,而load可加载多次

use require in script files and load in irb.

29. Time.now.strftime('%Y-%m-%d %H:%M:%S')

"str".rjust(10)

30.正则 /match/ =~ "str"? /regExp/.match(str)

31.<=>

[5,1,3,6,2,4,10,8].sort do |a, b|  -(a <=> b)end

32.attr_accessor

33.%r{regRex}