#Ò»¡¢Êý×éÒýÓÃ
arr=[3,4,5,6,7,8,9]
puts arr[0] #3
puts arr.first #3
puts arr[arr.length-1] #9
puts arr[arr.size-1] #9
puts arr.last #9
puts arr[-1] #9
puts arr[-2] #8
print arr[1..3] ,"\n" #456
print arr[-3,4] ,"\n" #789£¬´Ó-3¿ªÊ¼ £¬´òÓ¡4¸öÔªËØ£¬ÕâÀïÖ»ÓÐÈý¸ö
#RubyµÄÊý×é´óСÊǶ¯Ì¬µÄ£¬ÄãÄܹ»ËæʱÔö¼Ó¡¢É¾³ýÊý×éÔªËØ¡£
print arr.join(", "),"\n" #Òâ˼ÊÇ£º½«Êý×éarrת»»³É×Ö·û´®Êä³ö£¬ÓÃ", "¸ô¿ªÃ¿¸öÔªËØ£¬²¢ÇÒ»»ÐС£
#¶þ¡¢Êý×é±à¼
arr=[4,5,6]
print arr.join(", "),"\n" #4, 5, 6
arr[4] = "m" #°Ñ4ºÅË÷ÒýλÖÃÔªËظ³ÖµÎª"m"
print arr.join(", "),"\n" #4, 5, 6, , m
print arr[3] ,"\n" #´òÓ¡3ºÅË÷ÒýλÖÃÔªËØ #nil
arr.delete_at(3) #ɾ³ý3ºÅË÷ÒýλÖÃÔªËØ
print arr.join(", "),"\n" #4, 5, 6, m
arr[2] = ["a","b","c"] #°Ñ2ºÅË÷ÒýλÖÃÔªËظ³ÖµÎª["a","b","c"]
print arr.join(", "),"\n" #4, 5, a, b, c, m
print arr[2] ,"\n" #´òÓ¡2ºÅË÷ÒýλÖÃÔªËØ #abc
arr[0..1] = [7,"h","b"] #°Ñ0..1ºÅÔªËØÌ滻Ϊ7,"h","b"
puts arr[0];#ÓÉÊä³ö¿É¼û£¬ÔªËظöÊý¼ÓÁËÒ»¸ö£¬¼´Ìæ»»Ö®ºó£¬³ÉÁË0..2¶ÔÓ¦7,h,b
puts arr[1];
puts arr[2];
puts arr.size
print arr.join(", "),"\n" #7, h, b, a, b, c, m
arr.push("b" ) #¼ÓÈëÔªËØ"b"
print arr.join(", "),"\n" #7, h, b, a, b, c, m, b
arr.delete(["a","b","c"] ) #ɾ³ýÔªËØ["a","b","c"]
print arr.join(", "),"\n" #7, h, b, m, b
arr.delete("b") #ɾ³ýËùÓÐÔªËØ"b"
print arr.join(", "),"\n" #7, h, m
arr.insert(3,"d") #ÔÚ3ºÅË÷ÒýλÖòåÈëÔªËØ"d"
print arr.join(", "),"\n" #7, h, m, d
arr<<"f"<<2 #¼ÓÈëÔªËØ"f"£»¼ÓÈëÔªËØ2
print arr.join(", "),"\n" #7, h, m, d, f, 2
arr.pop #ɾ³ýβԪËØ
print arr.join(", "),"\n" #7, h, m, d, f
arr.shift #ɾ³ýÊ×ÔªËØ
print arr.join(", "),"\n" #h, m, d, f
arr.clear #Çå¿ÕÊý×éarr
print arr.join(", "),"\n"
#Èý¡¢Êý×éÔËËã
aaaa=[" aa ",4,5," bb "]
bbbb=[4,1,3,2,5]
print aaaa + bbbb ,"\n" # aa 45 bb 41325
print aaaa * 2 ,"\n" # aa 45 bb aa 45 bb
print bbbb - aaaa ,"\n" #132
#²¢ÔËË㣻½»ÔËËã
print aaaa | bbbb ,"\n" # aa 45 bb 132
print aaaa & bbbb ,"\n" #45
#ÅÅÐò£»µ¹ÖÃ
print bbbb.sort ,"\n" #12345
print aaaa.reverse ,"\n" # bb 54 a
´Ó½ñÌìÆð²»ÔÙÀË·Ñʱ¼ä£¬¿ªÊ¼×ßÏò×Ô¶¯»¯²âÊÔÕâÌõ¹âÃ÷µÄµÀ·£¬²¢ÒԴһ¸ö×Ô¶¯»¯²âÊÔƽ̨ΪĿ±ê£¬²¢Õâ¸ö¹ý³ÌÒ»µãµãµÄ¼Ç¼ÏÂÀ´ºÍ´ó¼Ò·ÖÏí
Ê×ÏÈ£¬ÊÇruby»·¾³µÄ´î½¨
£¨1£©µ½rubyµÄ¹ÙÍø£ºhttp://www.ruby-lang.org/en/ÏÂÔØ ruby°²×°³ÌÐò;
PS £ºÑ¡Ôñ ruby on windows,ÎÒÏÂÔصÄÊÇRuby 1.8.6 One ......
1. rubyÒѳÉΪ1.87
2. ±ØÐëÏÈ°²×°°²×°¹âÅÌÀïµÄеÄxcode£¬ÔÚ"optional"Ŀ¼Àï
3. ¿ÉÄÜÐèÒªÖØа²×°macport
http://trac.macports.org/wiki/Migration
4. »òÕßÉý¼¶macport
http://weblog.rubyonrails.org/2009/8/30/upgrading-to-snow-leopard
$ sudo port selfupdate
$ sudo port sync
$ sudo port upgrade --force insta ......
ΪÁËÑ¡ÔñÒ»¸öºÏÊʵĽű¾ÓïÑÔѧϰ£¬½ñÌì²éÁ˲»ÉÙÓйØPerl£¬Python£¬Ruby£¬JavascriptµÄ¶«Î÷£¬¿ÉÊÇ·¢ÏÖ¸÷´óÕóÓªµÄÈ˶¼ÔÚ´µÅõ×Ô¼ºÏ²»¶µÄÓïÑÔ£¬²»¹ý×îûÓÐÕùÒéµÄÓ¦¸ÃÊÇJavascriptÏֽ׶λ¹²»ÊʺÏÓÃÀ´×ö¶ÀÁ¢¿ª·¢£¬ËüµÄÌìÏ»¹ÊÇÔÚwebÓ¦ÓÃÉÏ¡£ ÎÒÖ÷ÒªÊÇÏë×öÊý¾ÝÍÚ¾òËã·¨µÄÑо¿£¬Ó¦¸Ã»á´¦Àí´óÁ¿µÄÎı¾¡£Ìáµ½Îı¾´¦Àí£¬ÏàÐŴ󲿷ÖÈË ......