摘要:
1.load( io )Load a document from the current io stream.File.open( 'animals.yaml' ) { |yf| YAML::load( yf ) } #=> ['badger', 'elephant', 'tiger']example:require 'yaml'yml = YAML::load(File.open('t.yml'))p yml Can also load from a string.YAML.load( &q 阅读全文
摘要:
1.sort → new_ary click to toggle sourcesort { |a, b| block } → new_aryReturns a new array created by sorting self.Comparisons for the sort will be done using the operator or using an optional code block.The block must implement a comparison between a and b, and return -1, when a follows b, 0 when a. 阅读全文
摘要:
由[索引, 值, ...] 型的数组变为哈希表ary = [1,"a", 2,"b", 3,"c"]p Hash[*ary]# => {1=>"a", 2=>"b", 3=>"c"}由索引和值配对出现的数组变为哈希表alist = [[1,"a"], [2,"b"], [3,"c"]]p Hash[*alist.flatten]#=> {1=>"a", 2=&g 阅读全文