Ò׽ؽØÍ¼Èí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Rubyѧϰ±Ê¼Ç¶þ——Êý×é

#Ò»¡¢Êý×éÒýÓÃ
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


Ïà¹ØÎĵµ£º

rails on ruby exmaples depot

1.install ruby
    download from http://www.ruby-lang.org/en/news/2009/12/07/ruby-1-9-1-p376-is-released/
2.install rails
   ruby gem install rails --include-dependencies
3.install mysql
   download from http://sourceforge.net
   ruby gem install&nb ......

Ruby ShoesµÄСÎÊÌâ

½ñÌì°ÑRuby Shoes´ò°üµÄ³ÌÐò¸´ÖƵ½Ã»Óа²×°Ruby ShoesµÄ»úÆ÷ÉÏ£¬·¢ÏÖËü»¹Ï²»ÁËRuby ShoesµÄ»·¾³°ü¡£
ÕâÈÃÎҸоõºÜ¾ÚÉ¥£¬ºÃ²»ÈÝÒ×ÈëÃÅÁËÒ»ÃÅÓïÑÔ£¬È´ÓöÉÏÁËÎÞ·¨²¿ÊðµÄÎÊÌâ¡£
ÉõÖÁ£¬ÎÒºóÀ´ÏëÒª°ÑÔËÐл·¾³Ç¶Èëµ½Ruby ShoesÖУ¬¶¼Ã»Äܹ»×öµ½¡£
ÕâÑùµÄÎÊÌâÕæÊÇÈÃÎҸоõµ½¶ÔShoesµÄʧÍû¡£
²»¹ý»¹ºÃ£¬³öÁËRuby Shoes£¬»¹Óкܶ ......

ruby£º²é¿´°æ±¾£¬ÃüÁîÐÐÔËÐгÌÐò


Ô­ÎÄÁ¬½Ó£º http://hi.baidu.com/%B7%CF%B2%C5%CB%FB%B8%E7/blog/item/09c19411244152daf7039ec4.html
ͨ¹ýÃüÁîÐв鿴ruby°æ±¾ÐÅÏ¢£º
ruby -v
ÃüÁîÐÐÔËÐгÌÐò£º
·½·¨1.
ruby -e 'print "hello ruby"'
-e ±íʾ½«ºóÃæµÄÒ»ÐÐ×÷Ϊruby³ÌÐò
print ÊÇrubyµÄÒ»¸öÄÚÖú¯Êý
·½·¨2.½»»¥±àÒë»·¾³
irb £¨ÃüÁîÐÐÊäÈëºó£¬ ......

Ruby ÃüÁîÐÐ ³£ÓÃÃüÁî

´ÓÃüÁîÐÐÆô¶¯Ruby½âÊÍÆ÷ʱ£¬Äã²»½ö¿ÉÒÔÌṩ³ÌÐòÎļþµÄÃû×Ö£¬¶øÇÒ¿ÉÒÔÌṩһ¸ö»ò¶à¸öÃüÁîÐпª¹Ø¡£ÄãÑ¡ÔñµÄ¿ª¹ØÖ¸Ê¾½âÊÍÆ÷ÒÔÒ»ÖÖÌØ¶¨µÄ·½Ê½ÔËת£¬²¢ÇÒ/»òÕßÖ´ÐÐÌØ¶¨µÄ²Ù×÷¡£
RubyÃüÁîÐпª¹ØÓÐ20¶à¸ö£¬ÆäÖÐÓÐЩºÜÉÙʹÓã¬ÓÐЩÔòÿÌì±»ºÜ¶àRuby³ÌÐòԱʹÓá£ÔÚÕâÀïÎÒÃǽ«ÔÙ¿´¼¸¸ö×î³£Óõġ££¨ÄãÒѾ­¿´µ½¹ýÆäÖеÄÁ½¸ö£¬-cºÍ&ndas ......

Perl£¬Python£¬Ruby£¬JavascriptËÄÖֽű¾ÓïÑԱȽÏ

ΪÁËÑ¡ÔñÒ»¸öºÏÊʵĽű¾ÓïÑÔѧϰ£¬½ñÌì²éÁ˲»ÉÙÓйØPerl£¬Python£¬Ruby£¬JavascriptµÄ¶«Î÷£¬¿ÉÊÇ·¢ÏÖ¸÷´óÕóÓªµÄÈ˶¼ÔÚ´µÅõ×Ô¼ºÏ²»¶µÄÓïÑÔ£¬²»¹ý×îûÓÐÕùÒéµÄÓ¦¸ÃÊÇJavascriptÏֽ׶λ¹²»ÊʺÏÓÃÀ´×ö¶ÀÁ¢¿ª·¢£¬ËüµÄÌìÏ»¹ÊÇÔÚwebÓ¦ÓÃÉÏ¡£ ÎÒÖ÷ÒªÊÇÏë×öÊý¾ÝÍÚ¾òËã·¨µÄÑо¿£¬Ó¦¸Ã»á´¦Àí´óÁ¿µÄÎı¾¡£Ìáµ½Îı¾´¦Àí£¬ÏàÐŴ󲿷ÖÈË ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØÍ¼ | ¸ÓICP±¸09004571ºÅ