Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB
ÈÈÃűêÇ©£º c c# c++ asp asp.net linux php jsp java vb Python Ruby mysql sql access Sqlite sqlserver delphi javascript Oracle ajax wap mssql html css flash flex dreamweaver xml
 ×îÐÂÎÄÕ : Ruby

rubyÎļþ²Ù×÷

1¡¢ÎļþµÄ´ò¿ªÓë¹Ø±Õ
    ``r'' Read-only, starts at beginning of file (default mode).
    ``r+'' Read-write, starts at beginning of file.
    ``w'' Write-only, truncates existing file to zero length or creates a new file for writing.
    ``w+'' Read-write, truncates existing file to zero length or creates a new file for reading and writing.
    ``a'' Write-only, starts at end of file if file exists, otherwise creates a new file for writing.
    ``a+'' Read-write, starts at end of file if file exists, otherwise creates a new file for reading and writing.
    ``b'' (DOS/Windows only) Binary file mode (may appear with any of the key letters listed above).
     ʹÓÃfile.new·½·¨»ñÈ¡Ò»¸öÎļþ¾ä±úÀ´¶ÔÎļþ²Ù×÷£¬²Ù×÷½áÊøºófile.closeÀ´¹Ø±ÕÎļþ¡£
     file.open·½·¨ÊÇnew·½·¨µÄÀ©³ä£¬¸Ã·½·¨¿ÉÓдúÂë¿é£¬¸Ã´ú ......

ubuntuÏ´ruby on rails

 Ò» °²×°ruby
$sudo apt-get install ruby irb rdoc
¶þ °²×°gem
1.µ½ÕâÀïÏÂÔØ ,×îºÃÊÇ×îа汾£¬ÎÒµÄ1.3.5
½âѹ£¬Çл»µ½µ±Ç°Ä¿Â¼£¬Ö´ÐÐ$sudo ruby setup.rb
»òÕßÕâÑù£º
$ tar xzvf rubygems-1.3.5.tgz   £¨½âѹ£©
$ cd rubygems-1.3.5     £¨Çл»µ½´ËĿ¼£©
$ sudo ruby setup.rb
2.gem -v ¼ì²â
Èç¹ûÓöµ½Ò»Ï´íÎó
/usr/bin/gem:10: undefined method `manage_gems' for Gem:Module (NoMethodError)
¾Ígem1.8 -v
»òÕßÖ´ÐдËÃüÁî
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem  £¨ÒªÈ·±£ÄãµÄrubyÊÇ1.8µÄ£¬»¹ÒªÈ·±£Äã×°µÄµØ·½£¬¿´×Ô¼º¶ø¶¨£©
ºóÔÙ³¢ÊÔgem -v
Èý °²×°rails
sudo gem install rails
ËÄ °²×°mysqlÇý¶¯
°²×°´ËÇý¶¯Ê±ÒªÈ·±£Èý¸ö°üÒÑ°²×°£¨libmysql-ruby1.8£¬libmysqlclient15-dev£¬ruby1.8-dev£©
ÏÂÔØmysql-ruby-2.8.tar.gz £¬
            $ tar xvzf mysql-ruby-2.8.tar.gz
            $ cd mysql-ruby-2.8
      &nb ......

Óà Ruby ²È²ÈËÄÈË°ï




ÉÏÉÏÖÜÔÚÊéµê¿´µ½Ò»±¾¡¶Ruby
Éè¼Æģʽ¡·£¬¼ñÆðÀ´ 10 ·ÖÖÓ¿´Í꣬ÈÓÁË£¨±ðÎÊÎÒΪʲô……£©
ÏÂÃæÓÃ Ruby
ддÉè¼Æģʽ£¬Ë³±ãÅúÒ»Åú Java ºÍ Gof
¡£
1.Factory
ºÍ Abstract Factory
class
 Factory  
  attr_accessor :product
  
  def
 produce  
    @product
.new
  
  end
  
end
  
class
 Product  
  #..
  
end
  
fac = Factory.new
  
fac.product = Product  
fac.produce  
class Factory
attr_accessor :product
def produce
@product.new
end
end
class Product
#..
end
fac = Factory.new
fac.product = Product
fac.produce
JavaдµÄ¹¤³§ÓÐÕâô¼òµ¥£¬ÕâôÈÝÒ×ÖØÓÃô£¿
2.Builder
# ¹¤Í·
  
class
 Director  
  def
 build_with builder  
 &nbs ......

Python, Ruby Óë Groovy£¬Ë­ÓëÕù·æ£¿

 SleekEngine
Ëæ׿ÆËã»úÓ²¼þµÄ¿ìËÙ·¢Õ¹£¬10ÄêÇ°ÒòΪËÙ¶ÈÎÊÌâ¶ø±»Ú¸²¡µÄJavaÏÖÔÚ³ÉÁ˼ÆËã»úÁ÷ÑÔÓïÑÔÖеÄÀϴ󣬵«ÊÇËüÈ´ÈÔ±»ÈÏΪ¸´ÔÓ±¿ÖØ£¬½ü¼¸ÄêÀ´¶¯Ì¬Óï
ÑÔÈ´ÓкóÀ´¸ÏÉϵÄÇ÷ÊÆ£¬ÕÆÎÕÒ»ÃŶ¯Ì¬ÓïÑÔ³ÉÁ˳ÌÐòÔ±ÐèÒª¿¼ÂǵÄÊÂÒË¡£ ½üÆÚ½Ó´¥Á˼¸ÖÖÁ÷ÐеĶ¯Ì¬ÓïÑÔPython, Ruby,
Groovy£¬ËüÃÇÏà±È¾²Ì¬ÓïÑÔJava/C++À´Ëµ£¬´óΪ¼òµ¥£¬Áé»î£¬Ê¡Ê±£¬ÄÇôѡÔñºÎÖÖÓïÑÔ£¿
dz³¢ÈýÖÖÓïÑÔºó£¬Ð´Ï´ËÎÄ£¬×÷ΪÔÚJavaEyeÁôµÄµÚһצ¡£
´ÓTIOBEÍøÕ¾µÄÓïÑÔÅÅÃû¿ÉÒÔ¿´³ö£¬±È½Ï2000Óë2008Ä꣬Java ´Ó30%µøµ½20%×óÓÒ, C++´Ó18%µøµ½11£¥£¬
¾²Ì¬ÓïÑÔ´Ó72%Õ¼ÓÐÂʽµµ½ÁË60%; ¶¯Ì¬ÓïÑÔÓÉ27%Éýµ½40%£¬ÆäÖÐPython´Ó1%µ½5%, RubyÓÉ <
1%µ½2.5%¡£PHPÓÉ5%³¤µ½11%¡£(ÒÔÉÏÊý¾ÝΪ´óÔ¼¹ÀËã)
´ÓÆóÒµ½ç½Ç¶È¿´£¬ÓïÑÔµÄÁ÷ÐÐÐÔÓëÒÔϼ¸µãÓйأº
1)  ³ÉÊìµÄ¿â(library)
   PythonµÄ¿â·Ç³£¶à£¬ Groovy¿ÉÒÔµ÷ÓÃÇ¿´óµÄJavaËùÓеĿ⣬ruby²îЩ£¬µ«ÊÇÕýÔÚ¸ÏÉÏ¡£
2) Á÷Ðпò¼Ü
  Èç¹ûijÖÖÓïÑÔÓиöÁ÷Ðпò¼Ü£¬ÄǾÍÄÜÎüÒý¹ýÀ´ºÜ¶àʹÓÃÕß¡£Ruby on RailÊÇɱÊÖ¼¶¿ò¼Ü¡£Python ¿ò¼ÜºÜ¶à£¬µ«ÊÇÄ¿Ç°ÉÐûÓÐÌرðÍ»³öµÄ¡£Groovy»¹ÄêÇᣬֻÓиöGrails£¬µ«ÊÇ¿ÉÒÔÀûÓÃJAVAÒÑÓеĿò¼ÜÈçSPRING HIBERNATE¡£
......

Python, Ruby Óë Groovy£¬Ë­ÓëÕù·æ£¿

 SleekEngine
Ëæ׿ÆËã»úÓ²¼þµÄ¿ìËÙ·¢Õ¹£¬10ÄêÇ°ÒòΪËÙ¶ÈÎÊÌâ¶ø±»Ú¸²¡µÄJavaÏÖÔÚ³ÉÁ˼ÆËã»úÁ÷ÑÔÓïÑÔÖеÄÀϴ󣬵«ÊÇËüÈ´ÈÔ±»ÈÏΪ¸´ÔÓ±¿ÖØ£¬½ü¼¸ÄêÀ´¶¯Ì¬Óï
ÑÔÈ´ÓкóÀ´¸ÏÉϵÄÇ÷ÊÆ£¬ÕÆÎÕÒ»ÃŶ¯Ì¬ÓïÑÔ³ÉÁ˳ÌÐòÔ±ÐèÒª¿¼ÂǵÄÊÂÒË¡£ ½üÆÚ½Ó´¥Á˼¸ÖÖÁ÷ÐеĶ¯Ì¬ÓïÑÔPython, Ruby,
Groovy£¬ËüÃÇÏà±È¾²Ì¬ÓïÑÔJava/C++À´Ëµ£¬´óΪ¼òµ¥£¬Áé»î£¬Ê¡Ê±£¬ÄÇôѡÔñºÎÖÖÓïÑÔ£¿
dz³¢ÈýÖÖÓïÑÔºó£¬Ð´Ï´ËÎÄ£¬×÷ΪÔÚJavaEyeÁôµÄµÚһצ¡£
´ÓTIOBEÍøÕ¾µÄÓïÑÔÅÅÃû¿ÉÒÔ¿´³ö£¬±È½Ï2000Óë2008Ä꣬Java ´Ó30%µøµ½20%×óÓÒ, C++´Ó18%µøµ½11£¥£¬
¾²Ì¬ÓïÑÔ´Ó72%Õ¼ÓÐÂʽµµ½ÁË60%; ¶¯Ì¬ÓïÑÔÓÉ27%Éýµ½40%£¬ÆäÖÐPython´Ó1%µ½5%, RubyÓÉ <
1%µ½2.5%¡£PHPÓÉ5%³¤µ½11%¡£(ÒÔÉÏÊý¾ÝΪ´óÔ¼¹ÀËã)
´ÓÆóÒµ½ç½Ç¶È¿´£¬ÓïÑÔµÄÁ÷ÐÐÐÔÓëÒÔϼ¸µãÓйأº
1)  ³ÉÊìµÄ¿â(library)
   PythonµÄ¿â·Ç³£¶à£¬ Groovy¿ÉÒÔµ÷ÓÃÇ¿´óµÄJavaËùÓеĿ⣬ruby²îЩ£¬µ«ÊÇÕýÔÚ¸ÏÉÏ¡£
2) Á÷Ðпò¼Ü
  Èç¹ûijÖÖÓïÑÔÓиöÁ÷Ðпò¼Ü£¬ÄǾÍÄÜÎüÒý¹ýÀ´ºÜ¶àʹÓÃÕß¡£Ruby on RailÊÇɱÊÖ¼¶¿ò¼Ü¡£Python ¿ò¼ÜºÜ¶à£¬µ«ÊÇÄ¿Ç°ÉÐûÓÐÌرðÍ»³öµÄ¡£Groovy»¹ÄêÇᣬֻÓиöGrails£¬µ«ÊÇ¿ÉÒÔÀûÓÃJAVAÒÑÓеĿò¼ÜÈçSPRING HIBERNATE¡£
......

Ruby 1.9²»»áɱËÀPython

Ëɱ¾ÐкêÈçÔ¼ÓÚÊ¥µ®½Ú·¢²¼ÁËRuby 1.9¡£¸ù¾ÝRubyµÄ¹ßÀý£¬Ð¡ÊýµãºóÃæµÚһλÈç¹ûÊǵ¥Êý£¬ÄÇô¾Í±íÃ÷ÕâÊÇÒ»¸öʵÑé°æ±¾£¬²»ÍƼöÓÃÓÚ²úÆ·»·¾³¡£Ëùν“²úÆ·»·¾³”£¬¶ÔÓÚÄ¿Ç°µÄRubyÀ´Ëµ£¬»ù±¾ÉϾÍÊÇRuby on Rails¡£´ÓÄ¿Ç°RoRÉçȺµÄ·´Ó³À´¿´£¬È·ÊµÓÐÈËÕýÔÚ³¢ÊÔÓÃRuby 1.9ÅäºÏRoR£¬µ«ÊÇÉÐÊôÍæƱÐÔÖÊ¡£ÎÒѯÎÊÁËһЩ´¦ÔÚÕæʵÏîÄ¿ÖеÄRoRÍŶӣ¬Ä¿Ç°»¹Ã»ÓÐÈË´òËãÔÚ×Ô¼ºµÄÏîÄ¿ÖÐʹÓÃRuby 1.9¡£
      ÔÚRubyÉçȺÀïµÄ°ëÏɼ¶ÈËÎïMauricio FernandezÔÚÕâÀï×ܽáÁËRuby 1.9µÄÖ÷ÒªÐÂÌØÐÔ£¬ÑóÑóÈ÷È÷µÄÒ»´óƪ£¬³ä³â׿¦Ã«ËâƤµÄÓï·¨ÌÇÒ£¬ÎÒ¿´ÁË°ëÌ죬ã¶ÊÇû¿´µ½¼¸¸öÌØÓÐÒâÒåµÄ¶«Î÷¡£ÆäʵRuby 1.9µÄ×îÖØ´ó±ä»¯ÔÚÄÚ²»ÔÚÍ⣬еÄÐéÄâ»úYarv°ÑRubyµÄÐÔÄÜ´ó´óÌá¸ßÁË¡£ÔÚCSDNÉϵÄһƪתÔر¨µÀÖÐÌáµ½£¬ÔÚÒ»¸öFibonacciÐòÁеÄÆÀ²â¶Ô±ÈÖУ¬Ruby 1.9µÄÐÔÄܽÏÖ®Python 2.5.1»¹Òª¿ì³öÁ½±¶¡£µ±È»£¬½öƾ½èÒ»¸ö²âÊԾͶ϶¨Ruby 1.9µÄÐÔÄÜ¿ìÓÚPythonÊÇÓ×Öɵģ¬µ«ÊÇÏÖÔÚ¿ÉÒԿ϶¨µØ˵£¬RubyÄÔ´üÉÏÄǶ¥“ËÙ¶È×îÂýµÄ¶¯Ì¬ÓïÑÔ”µÄ´óñ×ӿ϶¨ÒªÕªµôÁË¡£
      ÓÐÈËÈÏΪ£¬ÕâÏÂ×Ó²»µÃÁËÁË£¬RubyÒª³Æ°Ô¶¯Ì¬ÓïÑÔÁË¡£ÄãÏëÏ룬RubyÒѾ­¼¸ºõÓµÓÐÁËËùÓÐÃλ ......

ruby FileÔõôÔÚÔ´ÎļþµÄ»ù´¡ÉÏÌí¼ÓÄÚÈÝ£¬¶ø²»ÊÇÖØд

ÓÐЩͬѧÌáÎÊ£ºÎÒдÊý¾Ýµ½ÎļþÖлá°ÑÀϵÄÊý¾ÝÌæ»»µô¡£
ÔõôÔÚÔ´ÎļþµÄ»ù´¡ÉÏÌí¼ÓÄÚÈÝ£¬¶ø²»ÊÇÖØд
¡¾ruby code¡¿
  def txt_write(value,memo)
      File.open("c:\\my_text.txt", 'a') do |f|  
        f << "¶©µ¥±àºÅ£º#{value} #{memo}\n"
      end
  end
1¡¢openÔÚendµÄʱºò»á×Ô¶¯closeÎļþ
2¡¢File.open("c:\\my_text.txt", 'a')  # a¾ÍÊÇadd£¬ÏòÎļþÖÐÌí¼Ó×Ö·û.
3¡¢File.openÈç¹ûÔÚÎļþ·¾¶ÏÂûÓÐÕâ¸öÎļþ»á×Ô¶¯´´½¨²¢´ò¿ª£¬ÓоÍÖ±½Ó´ò¿ª.
......
×ܼǼÊý:146; ×ÜÒ³Êý:25; ÿҳ6 Ìõ; Ê×Ò³ ÉÏÒ»Ò³ [16] [17] [18] [19] 20 [21] [22] [23] [24] [25]  ÏÂÒ»Ò³ βҳ
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ