The Ruby FAQ

  1. °ò¥»°ÝÃD
  2. Ruby¹ï¡K¡K
  3. ¦w¸ËRuby
  4. »yªk
  5. ¨ä¥L¥\¯à

The Ruby FAQ

1. °ò¥»°ÝÃD

1.1 ­PÁµü

1.2 ¦ó¿×Ruby¡H

1.3 Åý§Ú¬Ý¨Ç¥ÎRuby¼g¦¨ªºµ{¦¡½X

1.4 ¬°¦ó­n¥s¡uRuby¡v¡H

1.5 Rubyªº¾ú¥v

1.6 Rubyªº¥D­¶¦b­þ¡H

1.7 ¦³µLRubyªº·s»D²Õ¡H

1.8 ¦³µLRubyªº¶l»¼½×¾Â¡H

1.9 RubyÁÙ¬Oruby¥¿½T¡H

1.10 ¦³µL¦³ÃöRubyªº®Ñ¡H

1.11 ¬Æ»ò½s¿è¾¹¤ä´©Ruby¡H

1.12

1.13

1.14 ¬Æ»ò¸ê®Æ¾A¦X·sRubyµ{¦¡­û¡H

1.15

1.16 Ruby¬Oª½Ä¶ÁÙ¬O½sĶªº¡H

1.17

1.18

1.19 ½Ö¥i¦^µª

­PÁµü

­ìµÛ¡J«e¥Ð­×§^( shugo{at}netlab.co.jp)¡C

²{¦b¥ÑDave Thomas¡]dave{at}pragmaticprogrammer.com ¡^ºûÅ@¡C¦hÁÂgotoken¡] gotoken{at}math.sci.hokudai.ac.jp¡^»s§@¤F­ì¨Óªº­^Ķ¥»¡A¥t¤]¦hÁÂDell¡¦Aquila¡BRobert Gustavsson Clemens Hintze¡BJosh Huber¡BH Morita¡BAleksi Niemela¡BHugh Sasse¡BConrad Schneiker¡BLarry W. Virden¡BJim Weirich¡A·íµM¤Ö¤£¤FMatz¡C


Ruby¬O­Ó²{¥Nªºª«¥ó¾É¦V»y¨¥¡A ´|¦X¤FPerl¡BSmalltalk©MSchemeªº¤¸¯À©ó¤@­Ó²³æ±j¤jªº»yªk¤§¤¤¡C³o¥÷¤å¥ó¼g¤F¤@¨Ç¸g±`³Q°Ý¨ì¦³ÃöRubyªº°ÝÃD©Mµª®×¡C³oùتºµ{¦¡½X¬O¥i¥H¥ÎRuby 1.6.8ª©¥»°õ¦æ¡C³o¥÷¤å¥óªºªk¤åª©¥i¥H¦brubyfr.org§ä¨ì¡C


1.2 ¦ó¿×Ruby?

Ruby¬O­Ó²¼ä±j¤jªºª«¥ó¾É¦Vµ{¦¡»y¨¥ ¡A¥Ñまつもと ゆきひろ(Yukihiro Matsumoto)¡]¦b³o¥÷¤å¥ó©M¶l»¼½×¾Â¤¤¨Ï¥Î¡umatz¡v³o­Ó¥~¸¹¡^¡C

¦PPerl¤@¼Ë¡ARuby¦³¨}¦nªº¤å¦r³B²z¯à¤O¡C¦n¹³Smalltalk¡A¦b RubyùØ¡A¤@¤Á¬Ò¬Oª«¥ó¡A¥t¥~Ruby ¦³°Ï¶ô(blocks), iterators, meta-classes ©M ¨ä¥L¦nªF¦è¡C

§A¥i¥H¥ÎRuby¨Ó¼g¦øªA¾¹¡Bexperiment with prototypes, ©M©Ò¦³¤é±`À³¥Î¡C§@¬°¤@­Ófully-integrated object-oriented language, Ruby scales well.

Ruby ¯S¦â¡J

1.2 Åý§Ú¬Ý¨Ç¥ÎRuby¼gªºµ{¦¡½X

Åý§Ú­Ì©w¸q¤@­ÓÃþ§O¥sPerson(¤H)¡A¦³name(¦W)©Mage(¦~ÄÖ)¡C§Ú­Ì·|³]­p¤@¨Ç¤HµM«á¤ÀªR¥L­Ì¡A¨Ó´ú¸Õ³o¨Çµ{¦¡½X¡C

  class Person
    attr_accessor :name, :age
    def initialize(name, age)
      @name = name
      @age  = age.to_i
    end
    def inspect
      "#@name (#@age)"
    end
  end

  p1 = Person.new('elmo', 4)
  p2 = Person.new('zoe', 7)

  puts p1
  puts p2

Now let¡¦s populate an array of people by reading their names and ages from a file containing lines like:

  bert:    8
  cookie: 11
  elmo:    4
  ernie:   8
  zoe:     7

³o¨Çµ{¦¡½X¨Ï¥Î¥¿³Wªí¥Ü¦¡¨ÓThe code uses regular expressions to parse successive lines from the input file, creating a new Person object for each match and pushing it on to the end of the array people.

  people = Array.new

  File.foreach("ages") do |line|
    people << Person.new($1, $2) if line =~ /(.*):\s+(\d+)/
  end

  people           # -> [bert (8), cookie (11), elmo (4), ernie (8), zoe (7)]

²{¦b¨Ì¤H­Ìªº¦~ÄֱƦn§Ú­Ìªºµ²ªG¡A¦³«Ü¦h¤èªk¥i¥H¿ì¨ìªº¡C§Ú­Ì¥i¥H©w¸q¤@­Ó±Æ§Çªº°Ï¶ô¡A§i¶DRuby ¦p¦ó¤ñ¸û¨â­Ó¤Hªº¥ý«á¦¸§Ç¡C

  sorted = people.sort { |a,b| a.age <=> b.age }
  sorted           # -> [elmo (4), zoe (7), bert (8), ernie (8), cookie (11)]

¥t¤@­Ó¤èªk¬O´ÀÃþ§O§ïÅÜ¡u¤ñ¸û¡vªºmethod Person:

  class Person
    def <=>(other)
      @age <=> other.age
    end
  end
  people.sort

1.3 ¬°¦ó­n¥sRuby¡H

¦bPerlªº¼vÅT¤U¡AMatz·Q¥Î¤@­ÓÄ_¥Ûªº¦W¦r§@¥Lªº·sµ{¦¡»y¨¥ªº¦W¦r©ó¬O¥L¨Ìa colleague's birthstone©R¦WRuby¡C

¨ä«á¥Lµo²{Ruby¦b«Ü¦hÀô¹Ò¤U³£±µµÛPerlªº¦ì¸m¡C ¬Ã¯](Perl­ì¦W¬OPearl)¬O¤»¤ëªº½Ï¥Í¥Û¡A¬õÄ_¥Û(ruby)«h¬O¤C¤ë¡C ­pºâ¦r«¬¤j¤pªº¸Ü¡Apearl¬O5pt¡Aruby¬O5.5pt¡C ¤@­Ó¤ñPerl¸û·s¡]¦P®É§Æ±æ¸û¦n¡^ªºµ{¦¡»y¨¥¡AMatz»{¬°Ruby¬O­Ó¦n¦W¦r¡C

(Based on an explanation from matz in [ruby-talk:00394] on June 11, 1999.)

1.5 Rubyªº¾ú¥v¡H

The following a summary of a posting made by Matz in [ruby-talk:00382] on June 4, 1999. (The birthday of Ruby is corrected in [ruby-list:15977]). ¶â¡ARuby½Ï¥Í©ó¤@¤E¤E¤T¦~¤G¤ë¤G¤Q¥|¤é¡C§Ú¥¿©M§Úªº¦P¨Æ½Í½×¤@­Óª«¥ó¾É¦Vªº©R¥O½Z»y¨¥ (object-oriented scripting language)¡C§Úª¾¹DPerl¡]Perl4¡A¤£¬OPerl5¡^¡A¦ý§Ú¯uªº¤£³ßÅw¥¦¡A¦]¬°¥¦¦³ÂIª±¨ãµ{¦¡»y¨¥ªº¨ý¹D¡]²{¦b¥¦ÁÙ¦³¡^¡C The object-oriented scripting language seemed very promising. §Ú¥ç»{ÃÑPython¡C¦ý§Ú¤£³ßÅw¥¦¡A¦]¬°§Ú¤£Ä±±o¥¦¬O¯u¥¿ªºª«¥ó¾É¦V»y¨¥¡X¡Xª«¥ó¾É¦Vªº¯S©Ê¦ü¥G¬O»y¨¥ªºªþÄÝ«~¡C§@¬°¤@¦ì»y¨¥manic©Mª«¥ó¾É¦Vªº¤ä«ùªÌfor 15 years¡A§Ú¯uªº·Q¤@­Ógenuine ª«¥ó¾É¦V¡B®e©ö¨Ï¥Îªº©R¥O½Z»y¨¥¡C§Ú¦b§ä´M¡A¦ý§ä¤£¨ì¡C ©ó¬O§Ú«K¨M©w¥h»s³y¥¦¡C¥¦¯Ó¤F´X­Ó¤ë¥h¥Oª½Ä¶¾¹¥i¹B§@¡C¦b¥¦¤W­±¡A§Ú©ñ¤F§Ú·Q­nªº¥\¯à¡A¨Ò¦p iterators, exception handling, garbage collection. Then, I reorganized the features of Perl into a class library, and implemented them. I posted Ruby 0.95 to the Japanese domestic newsgroups in Dec. 1995. Since then, highly active mailing lists have been established and web pages formed.

1.6 Rubyªº¥D­¶¦b­þùØ¡H

Rubyªº©x¤èºô¯¸¬O www.ruby-lang.org(­^¤å)©M www.ruby-lang.org/ja(¤é¤å)¡C

§A¥ç¥i¥H¦bwww.rubycentral.com§ä¨ìRubyªº¸ê®Æ¡C ¯S§Oªº¬O¡A§A¥i¥H¦bwww.rubycentral.com/book§ä¨ìProgramming Ruby³o¥»®Ñªº½u¤Wª©¥»¡C

Rubygarden¡Awww.rubygarden.com¬O¥t¤@­ÓÃö©óRubyªº¦nºô¯¸¡A¯S§O¤§³B¬O¦³Rubyªº·s®ø®§©MWiki¡C

1.7 ¦³µL¥ô¦óRubyªº·s»D²Õ¡H

¦b¤G¹s¹s¹s¦~¤­¤ëcomp.lang.ruby¥X²{¤F(±o­n¦hÁ Conrad Schneikerªº§V¤O)¡C

1.8 ¦³µL¥ô¦óÃö©óRubyªº¶l»¼½×¾Â¡H

¼È®É¦³¤­­Ó°Q½×Rubyªº¶l»¼½×¾Â¡C²Ä¤@­Ó¬O­^¤åªº¡A¨ä¾l¬O¤é¤å¡J

ruby-talk
: Rubyªº°Q½×¡]¨Ï¥Î­^¤å¡^
ruby-list
Rubyªº°Q½×¡]¨Ï¥Î¤é¤å¡^
ruby-dev
µ¹Ruby¶}µoªÌªº
ruby-ext
µ¹´ÀRuby¼¶¼gextensionsªº
ruby-math
Ruby¦b¼Æ¾Ç

³z¹Lblade.nagaokaut.ac.jp/ruby/ruby-talk/index.shtml.¡A¥i¥H·j´M¶l»¼½×¾ÂªºÀÉ®× ¡]³o¬O ruby-talkªºÃìµ²¡J munge as required for the others).

1.9 RubyÁÙ¬Oruby¥¿½T¡H

¥¿¦¡ªº»¡ªk¬O¡uRuby¡v¡C¦b¤j³¡¥÷ªº¨t²Î¡A¨Ï¥Î¡uruby¡v¨Ó°õ¦æRuby¡C¨Ï¥Îruby¨ú¥N Ruby¬O³\¥iªº¡C

½Ð¤Å¨Ï¥ÎRUBY¨Ó¬°³o­Óµ{¦¡»y¨¥ªº¦W¦r¡C

­ì¥»¥¦¬O¥s§@¡uruby¡vªº¡C

1.10 ¦³Ãö©óRubyªº®Ñ¶Ü¡H

½Ðª`·N¥H¤U³s©¹RubyGarden WikiªºÃìµ²¡Jwww.rubygarden.org/ruby?RubyBookList

¼w¤å®ÑÄy¡J

1.11 ¬Æ»ò½s¿è¾¹¤ä´©Ruby¡H

emacs/xemacs
www.gnu.org/software/emacs/emacs.html ©Îwww.xemacs.org" : ruby-mode.el is supplied in the Ruby distribution. With some versions of XEmacs, you may need to add (load "font-lock") to your .emacs file to allow ruby-mode.el to detect the syntax highlighting package you¡¦re using.
Vim
www.vim.org: Vim 5.7©M¥H«á §¡±NRubyªºsyntaxÀÉ®×§@¬°¼Ð·Çpackage¤ºªº¤@³¡¤À¡C¤§«eªºª©¥»ªºRubyªºsyntaxÀɮשñ¦bwww.xs4all.nl/~hipster/lib/ruby/ruby.vim¡C
JEdit
jedit.sourceforge.net: ¤@­Ó¥ÎJava¼gªº¸ó¥­»O½s¿è¾¹¡A¤ä«ùRuby¡C
Jed
space.mit.edu/~davis/jed.html: ¤@­Ó¤ä«ùRubyªºs-langÀÉ®×¥i©ówww.kondara.org/~g/slang/ruby.sl¨ú±o¡C
Nedit
www.nedit.org: Eric Santonacci has written Ruby support for Nedit, available from ftp.talc.fr/pub/ruby/ruby.nedit-0.1.tar.gz.
TextPad
Barry Shultz¼g¤F­ÓRubyªº©w¸qÀɮרÑTextPad¨Ï¥Î¡A¥i©ó www.textpad.com/add-ons/ntsyn.html¨ú±o¡C
͵ù¡J¥H¤Uªº½s¿è¾¹ªº²M³æ¬O¨ú¦Û³o¥÷¤å¥óªº­^¤åª©¦¹­¶ªºcomments
EMEditor¡B Hydra (Mac OS X)¡B KDevelop3 (Gideon)¡B CREdit¡B RDE (Ruby Development Enviroment on win2k/XP)(homepage2.nifty.com/sakazuki/rde_e.html)¡B Kate (KDE)¡B Crimson Editor(freeware)¡B syn(syn.sourceforge.net/)¡B SciTe (www.scintilla.org/SciTE.html)¡B BBEdit (Mac OS X)¡B SubEthaEdit (Mac OS X)¡K¡K

¦p¦ó§ä¨ìÀ°§U¡H

Rubyªº»yªk¦Ûª©¥»1.0«á¤w¸gí©w¤U¨Ó¡A¦ý·s¥\¯à¤´¤£Â_¼W¥[¡C ©Ò¥H®ÑÄy©Mºô¤W¤å¥ó¥i¯à·|¸ò¤£¤W¡C

­Y¦³°ÝÃD¡AÀH®É¥i©ó¶l»¼½×¾Â¤Wµo°Ý¡C¤@¯ë¨Ó»¡§A·|«Ü§Ö±o¨ì ¨Ó¦Ûmatz¡]Rubyªº§@ªÌ¡^¡B¨ä¥L¤j®v©M¤@¨Ç¸Ñ¨M¹LÃþ¦üªº°ÝÃDªº¤HªºµªÂСC

­YªG¬O¸ß°Ý¦³°ÝÃDªºµ{¦¡½X¡A½Ð±Nruby -vªº¿é¥X¤]¤@¨Ö°O¤U¡C

­Y§A¨Ï¥Îirb¡A¤p¤ß¥¦ªº¤@¨Ç­­¨î¡C¥Îirb -single-irb ¹Á¸Õ§AªºScript¡A©Îª½±µ¨Ï¥Îruby¡C

There might be similar questions in the mailing list, and it is good netiquette to read through recent mails (RFC1855:3.1.1, 3.1.2) before asking. But do ask on the list, and a correct answer will be forthcoming.

1.14 - ¬Æ»ò¸ê®Æ¾A¦X·sRubyµ{¦¡­û¡H

¥i©ówww.ruby-doc.org¤U¸üªºRuby Document Bundle¡A¥]§t¤F¤@¨Ç­«­nªº¤å¥ó©Mªì¾ÇªÌ±Ð ¾Ç¡Aas well as a "getting started" guide outlining all the resources available.

¨ä¤¤¤@­Óµ¹ªì¾ÇªÌªº­«­n¤å¥ó¬OWilliam Djaja Tjokroaminataªº§@«~¡C¥¦ÂI¥X¤Fªì¾ÇªÌ±`¥Çªº¿ù»~¡C

www.glue.umd.edu/~billtj/ruby.html

1.15 - Can I code and distribute desktop applications to people?

www.rubygarden.org/ruby?DistributeARubyAppInASingleExecutable has a fair bit of information about this.µª®×¬OªÖ©wªº¡A±a¦³¨â­Óĵ§i¡J

1.16 - Ruby¬Oª½Ä¶ÁÙ¬O½sĶªº¡H

Ruby¬Oª½Ä¶ªº¡CRubyªº¥¼¨Ó­p¹º¬OÁͪñ¤@­Ó½sĶªºµ{¦¡»y¨¥¡C ³o¥]¬A¤F³]­p¤@­ÓRubyVM (Rite / Ruby 2.0)¡A¤SºÙ§@Cardinal (Ruby frontend for ParrotVM)¡C Being interpreted does affect the speed of execution to some extent, but Ruby actually does pretty well in the language shootout rankings. ´¶¹M¨Ó»¡Rubyªº³t«×¤£·|©MPerl¤@¼Ë§Ö¡A¦ý¤£·|¤ñ¥¦¤Ó¹LºC¡C

1.17 - ¦p¦ó¨ÏVim¤ºÁYRubyªºµ{¦¡½X¡H

±N¥H¤U´X¦æ¥[¤J§Aªº .vimrc

  filetype plugin on "Turn ftplugins on
  filetype indent on "Turn ftindent on

¸Ô¨£www.rubygarden.org/ruby?VimRubySupport¡C

1.18 - RubyGarden Wiki¨Ï¥Î¬Æ»ò§@¬°backend¡H

RubyGarden wiki¬O«Ø°ò©óUsemodªº¡C¶â¡A¥¦¬O­ÓPerlªºµ{¦¡¡C§Ú(Dave)¨Ï¥ÎUsemod¨Ó§@§ÚªºWikis¡Jit is trivial to install and has zero maintenance. I considered writing an equivalent in Ruby, but why do that when there¡¦s a perfectly good solution out there? ¦]¬°²{¦bRuby¬°®Ú°òªºwiki¦w¸Ë¤W¦³°ÝÃD¡A©Ò¥H§Ú¤£±Ä¥Î¥¦­Ì¡C ³o­ÓFAQ¡]«ü­^¤åª©¡^¬O¥ÎRuby¼g¦¨ªºIowa¡C§Ú·Q¥Î¤@­Ó¯u¥¿ªº±M®×¨Ó´ú¸ÕIowa¡AÅý§Ú¥i¥H get my head around it.

1.19 ½Ö¥i¦^µª

#!¹ï­^¤åª©¦Ó¨¥¡A¤£¬O¹ï³o­Ó¤¤Ä¶¥»

There are a group of four or five folks who have update privileges¡J·í§Ú­Ì¬Ý¨ì°ÝÃD¡A·|¦³­Ó[ANSWER]Áä¥X²{¡A§Ú­Ì«ö¥¦¨Ó¼W¥[µª®×¡C

¦pªG¥ô¦ó¤H·Q°µ¦^µªªÌ¡A¥iµ¹§Ú¹q¶l¡C

Dave

Ruby¹ï¡K¡K

2.1 Ruby©MPython¬Û¤ñ¡H
2.2 Ruby¹ï¨ä¥L°ª¶¥°ÊºAµ{¦¡»y¨¥

2.1 Ruby©MPython¬Û¤ñ¡H

Python©MRuby§¡¬Oª«¥ó¾É¦Vªº»y¨¥¡A¬Ò´£¨Ñ¤F¤@­Ó¥Ñµ{§Ç¦¡ªº ¦Üª«¥ó¾É¦V½sµ{ªº¶ê¶¶Â½Ä¶¡C¬Û¹ï¨Ó»¡¡ASmalltalk ¥u¦³ª«¥ó¡X¡X§A¤£¥i¥H°µ¥ô¦ó¨Æ¡Aª½¦Ü§A©ú¥Õª«¥ó¡BÄ~©Ó©M the sizable Smalltalk class hierarchy¬°¤î¡C¬°¤F´£¨Ñ »²§Uµ¹µ{§Ç¦¡ªº½sµ{¡APython©MRuby¡u­×¸É¡v¤F¨ä¤¤¤@­Ó ¥\¯à¡A¥i¯à¥OSmalltalkÂ÷¶}¤F¥D¬y¡C³o¨â­Óµ{¦¡»y¨¥¥Î¹ï ¥ßªº¤èªk¨Ó¸Ñ¨M³o­Ó°ÝÃD¡C

Python¬O­Ó²VºØªº»y¨¥¡C¥¦¦³µ{§Ç¦¡½sµ{ªº¨ç¼Æ©Mª«¥ó ¾É¦V½sµ{ªºª«¥ó¡CPython¤¹³\¨ç¼Æ©Mmethods interconvert using the explicit ``self¡¦¡¦ parameter of every method def¡A¬°³o¨â­Ó¥@¬É«Ø°_¾ô¼Ù¡C When a function is inserted into an object, the first argument automagically becomes a reference to the receiver.

Ruby¬O¯Âª«¥ó¾É¦V»y¨¥¡A¥i¥H¸Ë§ê¦¨µ{§Ç¦¡ªº»y¨¥¡C¥¦ ¨S¦³¨ç¼Æ¡A¥u¦³method calls¡CIn a Ruby method the receiver, also called self, is a hidden argument like ``this¡¦¡¦ in C++. A ``def¡¦¡¦ statement outside of a class definition, which is a function in Python, is actually a method call in Ruby. These ersatz functions become private methods of class Object, the root of the Ruby class hierarchy. Procedural programming is neatly solved from the other direction - everything is an object. If the user doesn¡¦t grok objects yet, they can just pretend that ``def¡¦¡¦ is a function definition and still get useful work done.

Ruby¯Â²bªºª«¥ó¾É¦V¯S©Ê´£¨Ñ¤F¤@¤j°ïPython¨S¦³©Î¤D ¦b¤u§@ªº¥\¯à¡Ja unified type/class hierarchy, metaclasses, the ability to subclass everything, and uniform method invocation (none of this len() is a function but items() is a method rubbish). Ruby¹³Smalltalk¯ë ¶È¤ä«ù¤@Ä~©Ó¡A¦ý¥¦¦³«D±`±j¤jªºmix-in concept: a class definition may include a module, which inserts that module¡¦s methods, constants, etc. into the class.

Ruby, again like Smalltalk, provides closures and code blocks and uses them to the same good effect. The Ruby collection classes and iterators are outstanding, much more powerful and elegant than the ad hoc solutions that Python is sprouting (lambdas and list comprehensions).

Rubyªº»yªk©M³]­p­õ¾Ç¤j¨üPerlªº¼vÅT¡C¥¦ªº»yªk¦³«Ü¤j¼u©Ê¡C Statement modifiers ¡]if, unless, white, until µ¥µ¥¡^ ¥i¥H¥X²{©ó»y¥yªº§À³¡¡C¦s¦b¤@¨Ç¿ï¾Ü©ÊªºÃöÁä¦r¡]¨Ò¦pif»y¥y ùتºthen¡^¡Cmethod¤¤ªº¬A¸¹¦³®É¥i¥H¬Ù²¤ ³\¦h³\¦hªF¦èª½±µ¨ú¦ÛPerl¡C¤º«Øªº¥¿³Wªí¥Ü¦¡¡B$_©M¥¦ªº¥S§Ì¡B here documents¡B³æÂù¤Þ¸¹ªº¤À§O¡Bmethod¤¤ªº¬A¸¹¦³®É¥i¥H¬Ù²¤ ©M¨ä¥L¡C

­Y§A³ßÅwPerl¡A§A·|³ßÅwRuby¡Aı±oÀH¥¦ªº»yªk¦^¨ì®a¤¤¡C ­Y§A³ßÅwSmalltalk¡A§A·|³ßÅwRuby¡Aı±oÀH¥¦ªº»y¸q¦^¨ì®a¤¤¡C ­Y§A³ßÅwPython¡A§A©Î·|©Î¤£·|¦]Python©MRuby/Perlªº³]­p­õ¾Ç ªº¥¨¤j®t²§¦Ó¥¢¥h¿³½ì¡C

Ruby¤ñPython½ÆÂø±o¦h¤F¡A¦ý¥¦¤j³¡¤Àªº¥\¯à³£ºë±m¦a°t¦X¡C Ruby³]­p¬ü¦n¡Aº¡¬Oºë¤ß³]­pªº·N©À¡Athat might be mined for P3K. §Ú¤£ªÖ©w¦³¦h¤ÖPythonµ{¦¡³]­p®v±N·|ª`µø¨ìRuby¡X¡X ¥¦²{¦b©|¥¼¹Ü¥h§Úªº¤ß¡C¦ý¥¦¬O­È±o­«µø¡A ¨Ã¥i¥H¹ïPerl§@¥X¤@­Ó¯u¥¿ªº«Â¯Ù¡C

11/17/2000 John Dell¡¦Aquila©ócomp.lang.python
½Æ»sÀò±o±ÂÅv¡C

2.2 Ruby¹ï¨ä¥L°ª¶¥°ÊºAµ{¦¡»y¨¥

Ruby ¹ïSmalltalk ¹ï Objective-C ¹ï C++ ¹ï Java ¹ï Python ¹ï CLOS ¹ï Perl5 ¹ï PHP ¹ï Dylan¡C

¦b«Ü¦h¤HÀ°¦£¤U¡A§Ú­Ì»s¦¨¤F¤Uªí¡J

www.approximity.com/ruby/Comparison_rb_st_m_java.html

¥t¤@­Ó¡J

www.smallscript.com/Language%20Comparison%20Chart.asp

¦w¸ËRuby

3.1 ¬Æ»ò§@·~¨t²Î¤ä´©Ruby¡H
3.2 Rubyªº­ì©l½X¦b­þùØ¡H
3.3 §Ú¥i§_¨ú±oRubyªºdevelopment source tree¡H
3.4 ¦p¦ó½sĶRuby¡H
3.5 ¦p¦ó§i¶DRuby§Úªº¨ç¦¡®w¦b­þùØ¡H
3.6 ¦³¤w½sĶªºª©¥»¶Ü¡H
3.7 ¬Æ»ò¬O¡ucygwin¡v¡B¡umingw¡v©M¡udjgpp¡v¡H
3.8 ¬°¦óTkªº¹Ï¹³¤£¥i¦bWindows¤u§@¡H

3.1 ¬Æ»ò§@·~¨t²Î¤ä´©Ruby¡H

Ruby¦bLinux©³¤U«Ø³]¡A¥Ñ¬Û·í²³æª½±µªºC¼g¦¨¡C¥¦¥i°õ¦æ©óUNIX¡BDOS¡BWindows 95/98/NT/2000¡BMac OS X¡BBeOS¡BAmiga¡BAcorn Risc OS¤ÎOS/2¡C

Mac OS X 10.2¹w¥ý¦w¸Ë¤FRuby(Ruby 1.6.7 (2002-03-01) [powerpc-darwin6.0])¡C¸Ô¨£developer.apple.com/technotes/tn2002/tn2053.html.

H Morita ª`¡J

Ruby¦³Mac OS¡]¤£¬OX¡^ªºport¡A¥ÑHisakuni FUJIMOTO­t³d¡A©ñ¦bwww.fobj.com/hisa/old/ruby/. ¤£¹L¥¦¬O«Ø°ò©óRuby 1.1b7¡A¦Û¤G¹s¹s¤@¦~¤Q¤G¤ë¤]¤£´¿§ó·s¡C

  1. ¥¦¬O°ª«×¹êÅç©Êªº§@«~¡A¥i¯à¥O§Aªº¨t²Î°±µÛ¤£°Ê©Î·í¾÷¡C

³sRubyª©¥»¤ºªº½d¨Òscripts¤]¦³¾÷·|³y¦¨·í¾÷¡]¬Ý¨Ó®¼¦³½ìªº ;-¡^¡C

Salvador Parra Camacho»¡³oùئ³¨ÑOS/2¨Ï¥ÎªºRuby¡Jhobbes.nmsu.edu/pub/os2/dev/misc/rbemx164.zip

3.2 Rubyªº­ì©l½X¦b­þùØ¡H

³Ì·sª©¥»ªºRubyªº¤U¸ü³B¡Jwww.ruby-lang.org/en/20020102.html¡C¦b¸Ó­¶¥ç¦C¥X¤FÃè¹³¯¸¡C

¦P®É¦b¸Ó­¶¦³­Ó³s¦Vnightly snapshot of the development treeªºÃìµ²¡C

3.3 §Ú¥i§_¨ú±oRubyªºdevelopment source tree¡H

­Y§A¦³CVS client¡A§A¥i¥H¥Î¥H¤Uªº«ü¥O¨ú±o²{¦bªºsource tree¡J

  % cvs -d :pserver:[email protected]:/home/cvs login
  (Logging in to [email protected])
  CVS password: guest
  % cvs -d :pserver:[email protected]:/home/cvs co ruby

­YªG§A¨S¦³CVS¡A§A¥i¥H¥Ñftp.netlab.co.jp/pub/lang/ruby/snapshot.tar.gz¨ú±o¤@­Ónightly snapshot of the development source¡C

3.4 ¦p¦ó½sĶRuby¡H

Unix¤U¡ARuby¨Ï¥Îautoconf¨t²Î¨Ó³]©w½sĶÀô¹Ò¡C¤£¥²¨Ï¥Îautoconf«ü¥O¨Ó±q¤@­Óª©¥»«Ø¥ßRuby¡F¥u»Ý¥Î¥H¤U«ü¥O¡J

  % ./configure  [configure options]
  % make
  % make test
  % make install

­Y§A¤£¬O¤£ÅU¹w³]ªº¦w¸Ë¸ô®|(/usr/local)¡A´N¥i¯à»Ý­n¶W¯Å¨Ï¥ÎªÌªº¯SÅv¨Ó¦w¸ËRuby¡C§A¥i¥H¨Ï¥Î¥H¤U«ü¥O¨ú±o¤@¥÷configureªº¿ï¶µªº§¹¾ã¦Cªí¡J

  % ./configure --help 

­YªG§A¥ÑCVS archive¤u§@¡A§A¥i¯à»Ý­n¥ý°õ¦æ autoconf¡A¤~°õ¦æconfigure¡C

3.5 ¦p¦ó§i¶DRuby§Úªº¨ç¦¡®w¦b­þùØ¡H

¦b¬Y¨Ç¨t²Î¡A«Ø¥ßRubyªº°Ê§@¥i¯à·|¦]¬°§ä¤£¨ì¬Y¨Ç¥Î¤FÂX¥R®M¥ó¼Ò²Õ(extension modules)ªº¨ç¦¡®w¡]¨Ò¦pdbm¨ç¦¡®w¡^¦Ó¥¢±Ñ¡C

§A¥i¥H¨Ï¥Îconfigure¨Ó§i¶DRuby¦b­þùاä¨ç¦¡®w ¥Ñruby-talk:5041¡J

  ./configure --with-xxx-yyy=DIR

¦b¦¹¡Axxx¬O¥H¤U¨ä¤¤¤@­Ó¡J

  opt           extra software path in general
  dbm           path for dbm library
  gdbm          path for gdbm library
  x11           ...for X11..
  tk            ...for Tk...
  tcl           ...for Tcl...

¦Óyyy«h¥i¯à¬O

  dir           specifies -I DIR/include -L DIR/lib
  include       specifies -I DIR
  lib           specifies -L DIR

¦bHP-UX¡A¥Îgcc¨Ó«Ø¥ßRuby¥i¯à·|¦³°ÝÃD¡C¹Á¸Õ¨Ï¥ÎHP-UXªº½s;¹¡C WATANABE Tetsuya«ØÄ³¡J

  CC="cc -Ae" CFLAGS=-O ./configure --prefix=/opt/gnu

HPªº¤º¸mªºsed¥ç¥i¯à¦³°ÝÃD¡C¥L«ØÄ³¦w¸ËGNUªºsed¡C

3.6 ¦³¤w½sĶªºª©¥»¶Ü¡H

¥]¬A©Ò¦³ªF¦è§A»Ý­n¦b¦UºØWindows¤U¹B§@Rubyªº³æ¤@¤U¸üÀÉ®×¥i©ó rubyinstaller.rubyforge.org/wiki/wiki.pl§ä¨ì¡C ¦Û2002¦~¤¤¡A³o­Óª©¥»¨Ï¥ÎMicrosoft Visual C compiler¨Ó½sĶ¡C

¦pªG§A·Q­n¨ä¥L¦w¸Ëªº¿ï¾Ü¡A¨ÑWindows¨Ï¥Îªº¤w½sĶª©¥» ¥ç¥i¦bwww.os.rim.or.jp/~eban§ä¨ì¡C ­Y§A¤U¸ü¤Fruby-1.x.y-yyyymmdd-i386-cygwin.tar.gz¡]¬O­Ó¦n¿ï¾Ü¡^¡A §A¥ç­n¦b¸Ó­¶¤U¸ücygwin DLL¡C

Reuben Thomas¼g¹D¡J
Ruby¥ç²¾´Ó¤F©¹Acorn RISC OS¡Aª©¥»¬O1.4.3¡C§Ú»s³y¤F¥¦¡A¨ÃµL­p¹º¥hºûÅ@¥¦¡A¦ý§Ú¶Ç°e¤F¨º¨Çpatchesµ¹matz¡A©Ò¥H¸û·sªºª©¥»©Î¥i¨}¦n¦a½sĶ¡C

³o­Óµ¹Acorn¹q¸£¨Ï¥Îªº¤w½sĶª©¥»©ñ¤F©ówww.cl.cam.ac.uk/users/rrt1001/ruby.zip¡C

³¡¤À·N¨£

Steve Christensen©ó14-Aug-04 08:26»¡¡J
¨ÑSPARC/Solaris©Mx86/Solaris 8-9¨Ï¥ÎªºRuby 1.8.1¤w½sĶªºÀÉ®×¥i©ósunfreeware.com §ä¨ì

dublinclontarf©ó16-Aug-04 15:45»¡¡J
Slackware Linux¤W¨Ï¥ÎªºRuby 1.8.1¥i©ówww.linuxpackages.net§ä¨ì

3.7 ¬Æ»ò¬O¡ucygwin¡v¡B¡umingw¡v©M¡udjgpp¡v¡H

Rubyµ½¥Î¤FUnixÀô¹ÒªºÂ×´I¥\¯à¡C¤£©¯¦a¡AWindows¥¢¥h¤F¬Y¨Ç¥\¯à¡A¥BÃø¥H°õ¦æ¬Y¨Ç¥\¯à¡C¬G¦¹¦bWindows»Ý­n¤@¨Çmapping layer¨Ó°õ¦æRuby¡]¥H¤Î¨ä¥L¥HUnix¬°®Ú°òªºµ{¦¡¡^¡C

§A¥i¥Hµo²{¤£¦Pª©¥»ªºRuby°õ¦æÀÉ¡A¨Ï¥Î¤£¦Pªº¥]¸Ëªºmapping layers¡C

rbdj¬O­Ó¿W¥ßªºRuby Windows binaryª©¥»¡C¥¦¨Ï¥Î¤FDJ Delorieªº¤u¨ã¡]www.delorie.com¡^¡C

rbcw¬O­Ó»Ý­ncygwin libraryªºRuby Windows binary¡A¥i©ówww.cygwin.com©ÎRuby download pages§ä¨ì¡CCygwin¬O­Ó¼ÒÀÀ¼h©M¤@®M¥ÑCygnus Solutions¡]²{¦bRedhat¤½¥qªº¤@³¡¤À¡^»s³yªº¤u¨ã¡CRubyªºCygwinª©À³¸Ó¦³Windows¤U³Ì»ô¥þªº¥\¯à¡A©Ò¥H«Ü¦hµ{¦¡³]­p®v·|·Q¥Î¥¦¡C

­n¨Ï¥Îrbcwª©¥»¡A§A»Ý­n¿W¥ß¦w¸Ëcygwin.dll¡C·í§A¦w¸Ë¤Fcygwin¡A½Æ»scygwin1.dll¡]¥i¥H¦bcygwinªºbin§ä¨ì¡^¡A¶K©¹WINDOWS\system32¸ê®Æ§¨¡]©Î§Aªº¸ô®|¤¤ªº¬Y³B¡^¡C

·PÁÂAnders Schneiderman´£¨Ñ¤F³o¬q´y­zªº°ò¦¡C

3.8 ¬°¦óTkªº¹Ï¹³¤£¥i¦bWindows¤u§@¡H

  1. Tk¬O§_¥¿½T¦w¸Ë¦b§AªºWindows¡H©¹dev.scriptics.com/software/tcltk/§ä­Ó¤w½sĶTcl/Tkª©¥»¨Ñ§AªºWindows¨Ï¥Î¡C
  2. Àô¹ÒÅܼÆTCL_LIBRARY©MTK_LIBRARY ¬O§_«ü¦V¥]§tTcl©MTkªº¸ê®Æ§¨¡H
  3. Tkªº¨ç¦¡®w¬O§_¦b§Aªº¸ô®|ùØ¡H

»yªk

6.1 :var¬O¬Æ»ò·N«ä¡H
6.2 How can I access the value of a symbol?
6.3 loop¬O§_±±¨îµ²ºc¡H
6.4 How can I code post-test loops?
6.5 a +b³y¦¨¿ù»~¤F¡I
6.6 s = "x"; puts s *10 ³y¦¨¿ù»~¡C
6.7 Why can't I pass a hash literal to a method: p {}?
6.8 How can I call lvalue methods?
6.9 \1©M\1¦³¦ó¤À§O¡H
6.10 or©M||¦³¦ó¤À§O¡H
6.11 and©M&&¦³¦ó¤À§O¡H
6.12 Rubyùبº¨Ç¬J¤£¬O¦r¥À¤S«D¼Æ¦rªº²Å¸¹¬O¬Æ»ò¡H
6.13 $:, $!, $_µ¥²Å¸¹¬O¬Æ»ò·N«ä¡H
6.14 ¦ó¸Ñ (1210 / 100) ±o¥X12¦Ó«D12.1¡H

6.1 :var¬O¬Æ»ò·N«ä¡H

A colon followed by a name generates a Symbol object, represented externally as an integer. Symbols corresponds one to one with their corresponding identifiers. "var".intern gives the same integer as :var, but the ``:¡¦¡¦ form will create a local symbol if it doesn¡¦t already exist.

The routines catch, throw, autoload, and so on, require a string or a symbol as an argument.

method_missing, method_added and singleton_method_added (and others) require a symbol.

The fact that a symbol springs into existence the first time it is referenced is sometimes used to assign unique values to constants:

  NORTH = :NORTH
  SOUTH = :SOUTH
  EAST  = :EAST
  WEST  = :WEST

6.2 How can I access the value of a symbol?

To get the value of the variable corresponding to a symbol, you can use id2name to get the name of the variable, and then eval that to get that variable¡¦s contents. In the scope of "symbol", do eval(:symbol.id2name).
  a = 'This is the content of "a"'
  b = eval(:a.id2name)
  a.id == b.id  # b now references the same object as a

If your symbol corresponds to the name of a method, you can use the Method.method function to return a corresponding Method object, which you may then call.

  class Demo
    def meth
      puts "Hello, world"
    end
  end

  d = Demo.new
  m = d.method(:meth)
  m.call
Comments... By Mark Reed at 10-Feb-03 14:52:

It seems there should be a safer way of doing this. You can intern any string into a symbol, and calling id2name on the resulting symbol always gives you the original string back intact. So calling eval() on such a string when it has come from an external source is dangerous - yet I frequently wish to specify, say, the name of a class to use in a config file. It seems kludgy to use a regex to strip a string down to something safe and then apply the full power of eval on it just to find out what object that name maps to in the current runtime.

6.3 loop¬O§_±±¨îµ²ºc¡H

ÁöµMloop¬Ý¦ü±±¨îµ²ºc¡A¹ê»Ú¤W¥¦¬O­Ómethod¡A©w¸q©óKernel¡C The block which follows introduces a new scope for local variables.

6.4 How can I code post-test loops?

¦pªG§A»Ý­n´ú¸Õ°j°é§À³¡¡]¬Û¤Ï¦a¦b¶}ÀY¡^ªº±¡ªp¡A¨Ï¥ÎRubyªºbegin ... end¡A»Pwhile©Îuntil statement modifiers³o­Ó²Õ¦X¨Ó¨ú±o¬Û¦Pªº®ÄªG¡J

­ì¤å¡J If you need loops that test the condition at the end of the block, rather than at the start, use a combination of Ruby¡¦s begin ¡K end and the while or until statement modifiers to achieve the same effect:

i = 0
begin
  puts "i = #{i}"
  i +=1
end until i > 4

Ķª`¡J³o¬q½Tͱo¤£¤Ó¦n¡A¦]¬°§Ú¤£¤Ó²z¸Ñ

6.5 a +b³y¦¨¿ù»~¤F¡I

Ruby works hard to distinguish method calls from operators, and variable names from method names. ¤£©¯¦a¡A¥¦¨Ã«D¦¸¦¸·Ç½TµL»~¡C²{¦b¡ua +b¡v³Q¤ÀªR¦¨¡ua(+b)¡v¡C²¾¨«¡u+¡v¥ªÃ䪺ªÅ¥Õ©Î¦b¨ä¥k¼W¥[¤@­ÓªÅ¥Õ¡A¥¦·|³Q¤ÀªR¦¨¥[¼Æªº¤F¡C

6.6 s = "x"; puts s *10 ³y¦¨¿ù»~¡C

¦p¦P¤WÃD¡ARuby¬Ý¨ì¤£¹ïºÙªºªÅ¥Õ¡AµM«á±N¤§¤ÀªR¦¨puts(s(*10))¡]¯uªº¦³ÂI²Â¡K¡K¡^¡C¥Î¡us*10¡v©Î¡us * 10¡v¨Ó¨ú±o§A·Q­nªºµ²ªG½}¡C

6.7 Why can't I pass a hash literal to a method: p {}?

³o­Ó{}³Qµø¬°block¡A¦Ó«Dhashªººc³y¨ç¼Æ¡CYou can force the {} to be treated as an expression by making the fact that it¡¦s a parameter explicit: p({})

6.8 How can I call lvalue(¥ª­È) methods?

Ruby lets you define lvalue methods, methods that can receive a value from an assignment. However, these methods must be called with an explicit receiver, otherwise Ruby simply interprets the call as a variable assignment:

def pos=(val)
   @pos = val
end

pos = 123       # doesn't call method
self.pos = 456  # calls method

6.9 \1©M\1¦³¦ó¤À§O¡H

¥¦­Ì·N«ä¬Û¦P¡C¦b¥Î³æ¤Þ¸¹¥]µÛªº¦r¦êùØ¡A¥u¦³\¡¦©M\ are transformed and other combinations remain unchanged.

µL½×¦p¦ó¡A¦bÂù¤Þ¸¹¥]µÛªº¦r¦êùØ¡A"\1"¬O \001³o­Ó¦r¸`¡A"\1"ªí¥Ü¨â­Ó¦r²Å¦ê(character string) ¡A¥]¬A¤@­Ó­Ë±×½u©M"1"³o­Ó¦r¤¸¡C

6.10 or©M||¦³¦ó¤À§O¡H

||¦b¦¡¤lùسB²z¨â¶µ¸ê®Æ¡A

p(false || "Hello")

·|¼g¥XHello¡A¦]¬°¦b³o­Ó±ø¥ó¤U­º¶µ¸ê®Æ¬Ofalse¡A±j¨î ³B²z²Ä¤G¶µ¸ê®Æ¡C

¥t¤@¤è­±¡Aor¬O¥Î¨Ó¦b±ø¥óùسB²z¨â±ø¦¡¤l¡C

p(false or "Hello")

·|¾É­P»yªk¤ÀªR¿ù»~(parse error)¡A¦]¬°Ruby¤£±µ¨ü¤@­Ó±ø¥ó»y¥y¥X²{¦b¤Þ¼Æ¤º¡C

6.11 and©M&&¦³¦ó¤À§O¡H

¦³®É¡uand¡vªºÀu¥ý©Ê·|¤ñ¡u=¡v­n§C¡C¦³¨Ç¤H¦]¤U­±ªº¦¡¤l·P¨ì¤£¾A¡J

have_both = a and b

·|µ¥¦P¡J

(have_both = a) and b

§AÀ³±Ä¥Î¥H¤U¨ä¤¤¤@­Ó¤è®×¡J

have_both = a && b

have_both = (a and b)
if a and b
  # ...
end

Á`¬A¨Ó»¡¡A¡u&&¡v¾A¦X³B²z­È(values)¡F¡uand¡v¾A¦X³B²z¤Þ¼Æ(statements)¡C¤£À³¨Ï¥Î¡uand¡vªð¦^¥ô¦ó«D¥¬ªL­È¡C

¦pªGarr¬Onil¡A¤U­±ªº¦¡¤l¤]¤£·|¥X²{¿ù»~¡J

result = arr && arr.size

¤U­±¬Oif ... then ... else ...ªºÂ²¼g¡J

action() and
  LOG.info "Performed action" or
  LOG.info "Failed to perform action"

©Î³\·s¤â¹ï¦¹·P¨ì§x´b¡A¦ý¦pªG§A§â¥¦¬Ý¦¨¦ÛµM»y¨¥¡A±N«Ü§ÖÀ´±o¦p¦ó¹B¥Î¥¦¡C

ª`¡J¡]¡^¡C¡u&&¡vªºÀu¥ý©Ê¤ñ¡u||¡v¬°°ª¡C¦Ó¡uand¡v¸ò¡uor¡v«h¦³¬Û¦PªºÀu¥ý©Ê¡C

6.12 Rubyùبº¨Ç¬J¤£¬O¦r¥À¤S«D¼Æ¦rªº²Å¸¹¬O¬Æ»ò¡H

¤Uªí¬O°ò¥»ªººK­n¡F¸Ô¨£www.rubygarden.org/ruby?FunnySymbolsInCode¡A¥]¬A¨Ò¤l¡C

<=> <= < >= > == !=
Ãö«Y¹Bºâ¤l(Relational operators)¡A¥Î¨Ó¤ñ¸ûª«¥ó¡C<¥ç¥Î§@©w¸qclass inheritance()¡C
===
+ - * / % **
ºâ³N¹Bºâ¤l¡C%°£¤F¥Î¨Ó§@ºâ³N¹Bºâ¥~¡A¥ç¬Oprintf-style formattingªº±¶®|¡C
~ << >> & ^ |
: ?: ::
?c
?c¬Oc¦bASCIIªí¤Wªº­È¡]§Y99¡^¡C
!
ÅÞ¿è¤Wªº§_©w¡C
$
¥þ°ìÅܼơC
// %r{}
¥¿³Wªí¥Ü¦¡ªº©w¸q¡C
=~ !~
°t¹ï¥¿³Wªí¥Ü¦¡¡C
#{}
¦b³QÂù¤Þ¸¹¥]µÛªº¦r¦êùØ´¡¤Jªí¥Ü¦¡¡C
%q{} %Q{} %{}

6.13 $:, $!, $_µ¥²Å¸¹¬O¬Æ»ò·N«ä¡H

¥¦­Ì¬O¥þ°ìÅܼơ]©Ò¦³$xxx¬Ò¬O¥þ°ìÅܼơ^¡A¥]§t¤Fµ{¦¡ªº ­«­nªº¸ê®Æ©M¥¦ªº°õ¦æÀô¹Ò¡C¥¦­Ì¥ÑPerl°½¹L¨Óªº¡A¦Ó§Ú­Ì¹ªÀy§A±Ä¥Î ¤ñ¸û±µªñRubyªººD¥Î¤è¦¡¨Ó¨ú±o¸ê°T¡C

½Ð¨£"Ruby in a Nutshell"²Ä¤T³¹(Built-in Libraray Reference)¡A ¨ú±o¥¦­Ìªº¸ÑÄÀ¡C¥t¥i¬Ý¬Ý"English.rb"³o­ÓÀɮסA¥i¥H¥Îrequire English ¨Ó¨ú±o¥Î­^¤å¨Ó§@³o¨ÇÅܼƪº¦W¦r¡C¨Ò¦p¡J

alias $ERROR_INFO              $!
alias $FIELD_SEPARATOR         $;
alias $DEFAULT_OUTPUT          $>
alias $ARGV                    $*

6.14 ¦ó¸Ñ (1210 / 100) ±o¥X12¦Ó«D12.1¡H

¦pªG§A¶i¦æ¾ã¼Æ¬Û°£¡ARuby·|µ¹¥X¤@­Ó¾ã¼Æªºµª®×¡C ­n¨ú±o·Ç½Tªºµª®×¡A½ÐªÖ©w°£¼Æ¬O¯BÂI¼Æ¡C

1210 / 100             # -> 12
1210.0 / 100           # -> 12.1
1210 / 100.0           # -> 12.1
1210.0 / 100.0         # -> 12.1 

¤@¯ë¨Ó»¡¡A­nªÖ©wa¡Bbªº°Ó¬Oºë½Tªº¡A¥i¥H³o¼Ë°µ¡J

a.to_f / b

§A¥i¥H¥Î¤U­±ªº¤èªk¨ú±o¾l¼Æ¡]¾ã¼Æ¬Û°£¡^¡J

remainder = 1210 % 100    # -> 10
quot, rem = 1210.divmod(100)   # -> 12, 10

12 - ¨ä¥L¥\¯à

12.1 a ? b : c ¬O¬Æ»ò·N«ä¡H
12.2 ¦p¦ó­pºâÀɮתº¦æ¼Æ¡H
12.3 What do begin and end of MatchingData return?
12.4 «ç¼Ë­pºâ°}¦Cùتº¤¸¯À¤§©M¡H
12.5 continuations
12.6 Ruby¦³CGI¼Ò²Õ¶Ü¡H
12.7 best use of require

12.1 a ? b : c ¬O¬Æ»ò·N«ä¡H

§Yif a then b else c end¡A¥¦ÅýCµ{¦¡­û·P¨ì§ó¤è«K¡C

12.2 ¦p¦ó­pºâÀɮתº¦æ¼Æ¡H

±NÀɮ׳̧À¦³ªÅ¥Õ¦æ¤]­pºâ¦b¤º¡A¤U­±ªºµ{¦¡½X¥i¥Hµ¹¥X³Ì§Öªºµ²ªG¡C

open("ÀÉ®×").read.count("\n")

12.3 What do begin and end of MatchingData return?

12.4 «ç¼Ë­pºâ°}¦Cùتº¤¸¯À¤§©M¡H

12.5 continuations

12.6 Ruby¦³CGI¼Ò²Õ¶Ü¡H

·íµM¦³°Õ¡Acgi.rb¬ORubyªº¼Ð·Ç¨ç¦¡®wªº¤@¤À¤l¡C §A¥i¥H¾\Ū"Programming Ruby" (chapter "Ruby and the Web")¨Ó¤F¸Ñ¥¦¡C

Other packages of interest are: * CGIKit (framework) * Amrita (templating library) * Narf (web library)

¥H¤W§¡¥i¦bRAA§ä¨ì¡C

12.7 best use of require

1
Hosted by www.Geocities.ws