﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-Treacle-随笔分类-ROR</title><link>http://www.blogjava.net/Blake/category/1583.html</link><description>Java Toxication!</description><language>zh-cn</language><lastBuildDate>Wed, 07 Mar 2007 18:30:04 GMT</lastBuildDate><pubDate>Wed, 07 Mar 2007 18:30:04 GMT</pubDate><ttl>60</ttl><item><title>&lt;image src='http://www.blogjava.net/images/blogjava_net/blake/Misc/ruby.gif'/&gt;Get total lines of files</title><link>http://www.blogjava.net/Blake/archive/2005/06/18/6311.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Sat, 18 Jun 2005 04:24:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/18/6311.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/6311.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/18/6311.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/6311.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/6311.html</trackback:ping><description><![CDATA[<P><FONT face=Arial size=2>This is one small tools to get the total file line number of on folder.</FONT></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">POST_FIX&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;%w{java&nbsp;jsp&nbsp;html&nbsp;xml&nbsp;properties}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>EXCLUDE_DIR&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;%w{CVS}<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$displayStr&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$fileReg&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">$dirReg&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">\\.|\\.\\.|"<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">def&nbsp;sumLine(fileName)<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;file&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;open&nbsp;fileName<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;begin<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">while</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;file.gets()<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT face=Arial size=2>12</FONT></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;ensure<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;file.close<BR></SPAN><SPAN style="COLOR: #008080">14</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT face=Arial size=2>15</FONT></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;$.<BR></SPAN><SPAN style="COLOR: #008080">16</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT face=Arial size=2>17</FONT></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">18</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>def&nbsp;iteDir(name,&nbsp;level</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">0</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">)<BR></SPAN><SPAN style="COLOR: #008080">19</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;lines&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">20</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;dir&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;Dir.open&nbsp;name<BR></SPAN><SPAN style="COLOR: #008080">21</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;rex&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">/\</SPAN><SPAN style="COLOR: #000000">.&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">java</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">$|</SPAN><SPAN style="COLOR: #000000">\</SPAN><SPAN style="COLOR: #000000">.jsp$|</SPAN><SPAN style="COLOR: #000000">\</SPAN><SPAN style="COLOR: #000000">.html$</SPAN><SPAN style="COLOR: #000000">/</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT face=Arial size=2>22</FONT></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;begin<BR></SPAN><SPAN style="COLOR: #008080">23</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;dir.</SPAN><SPAN style="COLOR: #0000ff">each</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">do</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;|fileName|<BR></SPAN><SPAN style="COLOR: #008080">24</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;fileName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;dir.path&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #008000">'</SPAN><SPAN style="COLOR: #008000">/'&nbsp;+&nbsp;fileName</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">25</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;File.ftype(fileName)&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">~&nbsp;</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">directory</SPAN><SPAN style="COLOR: #000000">/</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">26</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">not</SPAN><SPAN style="COLOR: #000000">&nbsp;fileName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">~&nbsp;Regexp.</SPAN><SPAN style="COLOR: #0000ff">new</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">($dirReg)<BR></SPAN><SPAN style="COLOR: #008080">27</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;iteDir(fileName,&nbsp;level</SPAN><SPAN style="COLOR: #000000">+</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">)<BR></SPAN><SPAN style="COLOR: #008080">28</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">29</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">next</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">30</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">31</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif&nbsp;fileName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">~&nbsp;Regexp.</SPAN><SPAN style="COLOR: #0000ff">new</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">($fileReg)<BR></SPAN><SPAN style="COLOR: #008080">32</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;lines&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;sumLine(fileName)<BR></SPAN><SPAN style="COLOR: #008080">33</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">34</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT face=Arial size=2>35</FONT></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;ensure<BR></SPAN><SPAN style="COLOR: #008080">36</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;dir.close<BR></SPAN><SPAN style="COLOR: #008080">37</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">38</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;str&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">39</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">for</SPAN><SPAN style="COLOR: #000000">&nbsp;i&nbsp;in&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN><SPAN style="COLOR: #000000">..(level</SPAN><SPAN style="COLOR: #000000">-</SPAN><SPAN style="COLOR: #000000">1</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">)<BR></SPAN><SPAN style="COLOR: #008080">40</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\t|"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">41</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">42</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;level&nbsp;!</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">0</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">43</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;str&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">---"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">44</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">45</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;$displayStr&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">#{str}#{name}\t#{lines}&nbsp;lines\n#{$displayStr}"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">46</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;&nbsp;lines<BR></SPAN><SPAN style="COLOR: #008080">47</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><SPAN style="COLOR: #008080"><FONT face=Arial size=2>48</FONT></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">49</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>POST_FIX.</SPAN><SPAN style="COLOR: #0000ff">each</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">do</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;|postfix|<BR></SPAN><SPAN style="COLOR: #008080">50</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;$fileReg&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\.#{postfix}$|"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">51</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">52</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$fileReg&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;$fileReg.chop<BR></SPAN><SPAN style="COLOR: #008080">53</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">54</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>EXCLUDE_DIR.</SPAN><SPAN style="COLOR: #0000ff">each</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">do</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;|excludeDir|<BR></SPAN><SPAN style="COLOR: #008080">55</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;$dirReg&nbsp;</SPAN><SPAN style="COLOR: #000000">+=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">^#{excludeDir}$|"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">56</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">57</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>$dirReg&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000">&nbsp;$dirReg.chop<BR></SPAN><SPAN style="COLOR: #008080">58</SPAN></FONT></FONT><FONT face=Arial><FONT size=2><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">59</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>print&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Total&nbsp;#{iteDir(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">E:</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">_MyWorkSpace</SPAN><SPAN style="COLOR: #000000">/</SPAN><SPAN style="COLOR: #000000">IDEA_Proj</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)}&nbsp;lines\n"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT face=Arial><FONT size=2><SPAN style="COLOR: #008080">60</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">print&nbsp;$displayStr</SPAN></FONT></FONT></DIV></DIV><BR><FONT face=Arial size=2><STRONG><FONT color=#ff0000>Keystone:<BR></FONT></STRONG>&nbsp;&nbsp;&nbsp;1. Ruby I/O access. Dir and File<BR>&nbsp;&nbsp;&nbsp;2. Regexp &amp; String -&gt; Regexp<BR>&nbsp;&nbsp;&nbsp;3. Some kinds of variables<BR>&nbsp;&nbsp;&nbsp;4. Array operation</FONT> 
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/Ruby" rel=tag>Ruby</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/17/6311.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/17/6311.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/6311.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-18 12:24 <a href="http://www.blogjava.net/Blake/archive/2005/06/18/6311.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>&lt;image src='http://www.blogjava.net/images/blogjava_net/blake/Misc/ruby.gif'/&gt;Use Ruby send email</title><link>http://www.blogjava.net/Blake/archive/2005/06/16/6232.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Thu, 16 Jun 2005 11:38:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/16/6232.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/6232.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/16/6232.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/6232.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/6232.html</trackback:ping><description><![CDATA[<FONT face=Arial size=2>Today I'll show you how to send email with Ruby:<BR><BR></FONT>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<DIV><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">&nbsp;1</SPAN>&nbsp;<SPAN style="COLOR: #000000">require&nbsp;</SPAN><SPAN style="COLOR: #008000">'</SPAN><SPAN style="COLOR: #008000">net/smtp'</SPAN></FONT></FONT><SPAN style="COLOR: #008000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">&nbsp;2</SPAN>&nbsp;<SPAN style="COLOR: #008000"></SPAN><SPAN style="COLOR: #000000">SMTP_HOST&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><FONT size=2><FONT face=Arial><SPAN style="COLOR: #000000">192.168.60.99"<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">&nbsp;4</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #000000">def&nbsp;send(from,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">to</SPAN></FONT></FONT><FONT size=2><FONT face=Arial><SPAN style="COLOR: #000000">,&nbsp;subject,&nbsp;msg)<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;mail&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">To:&nbsp;#{to}\r\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">&nbsp;6</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">From:&nbsp;#{from}\r\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">&nbsp;7</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Subject:&nbsp;#{subject}\r\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">&nbsp;8</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">\r\n</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">+</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">&nbsp;9</SPAN>&nbsp;</FONT></FONT><FONT size=2><FONT face=Arial><SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;msg<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN>&nbsp;</FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">11</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;Net::SMTP.start(SMTP_HOST)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">do</SPAN></FONT></FONT><FONT size=2><FONT face=Arial><SPAN style="COLOR: #000000">&nbsp;|smtp|<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;&nbsp;&nbsp;smtp.send_mail(mail,&nbsp;from,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">to</SPAN></FONT></FONT><FONT size=2><FONT face=Arial><SPAN style="COLOR: #000000">)<BR></SPAN><SPAN style="COLOR: #008080">13</SPAN>&nbsp;<SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">14</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">end</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">15</SPAN>&nbsp;</FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">16</SPAN>&nbsp;<SPAN style="COLOR: #000000">from&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">blake@192.168.60.99"</SPAN></FONT></FONT><SPAN style="COLOR: #000000"><BR></SPAN><FONT size=2><FONT face=Arial><SPAN style="COLOR: #008080">17</SPAN>&nbsp;<SPAN style="COLOR: #000000"></SPAN><SPAN style="COLOR: #0000ff">to</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;[</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">blake@192.168.60.99</SPAN><SPAN style="COLOR: #000000">"</SPAN></FONT></FONT><FONT size=2><FONT face=Arial><SPAN style="COLOR: #000000">]<BR></SPAN><SPAN style="COLOR: #008080">18</SPAN>&nbsp;<SPAN style="COLOR: #000000">send(from,&nbsp;</SPAN><SPAN style="COLOR: #0000ff">to</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">test</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">Just&nbsp;a&nbsp;test!\ntest</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">)</SPAN></FONT></FONT></DIV></DIV><BR><FONT face=Arial size=2><STRONG><EM><FONT color=#ff0000>Notice:</FONT></EM></STRONG><BR>1. '<STRONG>mail</STRONG>' is the email body, it use <FONT style="BACKGROUND-COLOR: #ffff00">"\r\n"</FONT> to separate the mail header and mail context. So if you only want to send context without header, you should write: "mail = "\r\n" + msg". Otherwise your email will lost the context.</FONT> 
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/Ruby" rel=tag>Ruby</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/16/6232.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/16/6232.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/6232.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-16 19:38 <a href="http://www.blogjava.net/Blake/archive/2005/06/16/6232.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Ruby概述</title><link>http://www.blogjava.net/Blake/archive/2005/06/16/6221.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Thu, 16 Jun 2005 09:04:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/16/6221.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/6221.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/16/6221.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/6221.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/6221.html</trackback:ping><description><![CDATA[<FONT face=Arial><FONT size=2>&nbsp;</FONT><FONT size=2>Ruby是面向对象的编程语言，她追求的是“简便快捷的面向对象编程”。Ruby是解释型语言，因此不需编译即可快捷地编程。同时Ruby具有类似 Perl的强大的文本处理功能，她可并不只是个玩具，您可以用她来进行实用的编程。此外，您还可以很方便地使用C语言来扩展Ruby的功能，因此可以把她当作各种库的前端来使用。</FONT></FONT> 
<DIV class=body>
<DIV class=section>
<P><FONT face=Arial size=2>若您曾经“想要一种简单的面向对象的语言”，或者认为“Perl的功能虽然好用，但它的语法真让人受不了”，又或者觉得“lisp系列语言的思想不错，但到处都是括号真让人讨厌，最起码算式应该按照通常的样式书写”。那么，Ruby或许能让您满意。</FONT></P>
<P><FONT face=Arial size=2>归纳以来，Ruby有以下优点。</FONT></P>
<DL>
<DT><FONT face=Arial size=2><STRONG>解释器</STRONG></FONT> 
<DD><FONT face=Arial size=2>Ruby是解释型语言，其程序无需编译即可轻松执行。</FONT> 
<DT><FONT face=Arial size=2><STRONG>变量无类型</STRONG></FONT> 
<DD><FONT face=Arial size=2>Ruby的变量没有类型，因此不必为静态的类型匹配而烦恼。相应地，错误检查功能也变弱了。</FONT> 
<DT><FONT face=Arial size=2><STRONG>不需要变量声明</STRONG></FONT> 
<DD><FONT face=Arial size=2>所有变量均无需声明即可立即使用。另外，<FONT style="BACKGROUND-COLOR: #ffff00">从变量名即可判断出是何种变量</FONT>（局部变量，全局变量，实例变量）。</FONT> 
<DT><FONT face=Arial size=2><STRONG>语法简单</STRONG></FONT> 
<DD><FONT face=Arial size=2>语法比较简单，类似Algol系语法。</FONT> 
<DT><FONT face=Arial size=2><STRONG>不需要内存管理</STRONG></FONT> 
<DD><FONT face=Arial size=2>具有垃圾回收（Garbage Collect，GC）功能，能自动回收不再使用的对象。</FONT> 
<DT><FONT face=Arial size=2><STRONG>一切都是对象</STRONG></FONT> 
<DD><FONT face=Arial size=2>Ruby从一开始就被设计成纯粹的面向对象语言，因此以整数等基本数据类型为首的所有东西都是对象，它们都有发送信息的统一接口。<EM><FONT color=#008000>（这方面连Java都不如Ruby）</FONT></EM></FONT> 
<DT><FONT face=Arial size=2><STRONG>类，继承，方法</STRONG></FONT> 
<DD><FONT face=Arial size=2>Ruby当然具有面向对象语言的基本功能。</FONT> 
<DT><FONT face=Arial size=2><STRONG>特殊方法</STRONG></FONT> 
<DD><FONT face=Arial size=2>可向某对象添加方法。例如，可以把GUI按钮被按下时的动作作为方法记述下来，还可以用它来进行原型库（prototypebase）的面向对象编程（有人这么干吧）。</FONT> 
<DT><FONT face=Arial size=2><STRONG>用模块进行混合插入（Mixin）</STRONG></FONT> 
<DD><FONT face=Arial size=2>Ruby故意舍弃了多重继承，但拥有混合插入功能。使用模块来超越类的界限来共享数据和方法等。</FONT> 
<DT><FONT face=Arial size=2><STRONG>迭代器</STRONG></FONT> 
<DD><FONT face=Arial size=2>该功能可以将循环抽象化。</FONT> 
<DT><FONT face=Arial size=2><STRONG>闭包</STRONG></FONT> 
<DD><FONT face=Arial size=2>可以将某过程片段对象化。对象化后的该过程片段就称作闭包。</FONT> 
<DT><FONT face=Arial size=2><STRONG>功能强大的字符串操作／正则表达式</STRONG></FONT> 
<DD><FONT face=Arial size=2>以Perl为样板创造出了功能强大的字符串操作和正则表达式检索功能。</FONT> 
<DT><FONT face=Arial size=2><STRONG>拥有超长整数</STRONG></FONT> 
<DD><FONT face=Arial size=2>添加超长整数功能后，可以计算非常大的整数。例如计算400的阶乘也轻而易举。</FONT> 
<DT><FONT face=Arial size=2><STRONG>具有错误处理功能</STRONG></FONT> 
<DD><FONT face=Arial size=2>错误处理功能可以使您编写代码处理出错情况。</FONT> 
<DT><FONT face=Arial size=2><STRONG>可以直接访问OS</STRONG></FONT> 
<DD><FONT face=Arial size=2>Ruby可以使用（UNIX的）绝大部分的系统调用。单独使用Ruby也可以进行系统编程。</FONT> 
<DT><FONT face=Arial size=2><STRONG>动态加载</STRONG></FONT> 
<DD><FONT face=Arial size=2>若OS支持的话，可以在运行时读入对象文件。</FONT></DD></DL>
<P><FONT face=Arial size=2>但Ruby也有下列缺点。</FONT></P>
<UL>
<LI><FONT face=Arial size=2>因为Ruby是解释型语言，所以速度较慢</FONT> 
<LI><FONT face=Arial size=2>静态检查比较少</FONT></LI></UL></DIV></DIV>
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/Ruby" rel=tag>Ruby</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/16/6221.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/16/6221.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/6221.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-16 17:04 <a href="http://www.blogjava.net/Blake/archive/2005/06/16/6221.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>&lt;image src='http://www.blogjava.net/images/blogjava_net/blake/Misc/ruby.gif'/&gt;Ruby Http client</title><link>http://www.blogjava.net/Blake/archive/2005/06/02/5476.html</link><dc:creator>Blake HAN</dc:creator><author>Blake HAN</author><pubDate>Thu, 02 Jun 2005 08:52:00 GMT</pubDate><guid>http://www.blogjava.net/Blake/archive/2005/06/02/5476.html</guid><wfw:comment>http://www.blogjava.net/Blake/comments/5476.html</wfw:comment><comments>http://www.blogjava.net/Blake/archive/2005/06/02/5476.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.blogjava.net/Blake/comments/commentRss/5476.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/Blake/services/trackbacks/5476.html</trackback:ping><description><![CDATA[<P><FONT face=Georgia><FONT size=6>A</FONT>n example shows how to use Ruby write an HTTP client.</FONT></P>
<DIV style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: rgb(230,230,230) 0% 50%; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid; moz-background-clip: initial; moz-background-origin: initial; moz-background-inline-policy: initial">
<DIV><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: rgb(0,0,0)">require&nbsp;</SPAN><SPAN style="COLOR: rgb(0,128,0)">'</SPAN><SPAN style="COLOR: rgb(0,128,0)">net/http'</SPAN><SPAN style="COLOR: rgb(0,128,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">def&nbsp;fetch(</SPAN><SPAN style="COLOR: rgb(0,0,255)">loc</SPAN><SPAN style="COLOR: rgb(0,0,0)">,&nbsp;port,&nbsp;url)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;z</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">nil<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;h</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">Net::HTTP.</SPAN><SPAN style="COLOR: rgb(0,0,255)">new</SPAN><SPAN style="COLOR: rgb(0,0,0)">(</SPAN><SPAN style="COLOR: rgb(0,0,255)">loc</SPAN><SPAN style="COLOR: rgb(0,0,0)">,port)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;begin<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp,&nbsp;data&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;h.</SPAN><SPAN style="COLOR: rgb(0,0,255)">get</SPAN><SPAN style="COLOR: rgb(0,0,0)">(url,z)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">Code&nbsp;=&nbsp;#{resp.code}&nbsp;#{resp.message}"</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;resp.</SPAN><SPAN style="COLOR: rgb(0,0,255)">each</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;{|key,&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">val</SPAN><SPAN style="COLOR: rgb(0,0,0)">|&nbsp;printf&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">%-14s&nbsp;=&nbsp;%-40.40s\n</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">,&nbsp;key,&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">val</SPAN><SPAN style="COLOR: rgb(0,0,0)">}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;data<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;rescue&nbsp;Net::ProtoFatalError&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">=&gt;</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;detail<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;detail.data<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;head.</SPAN><SPAN style="COLOR: rgb(0,0,255)">each</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;{|key,</SPAN><SPAN style="COLOR: rgb(0,0,255)">val</SPAN><SPAN style="COLOR: rgb(0,0,0)">|&nbsp;puts&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">#{key}&nbsp;&nbsp;&nbsp;&nbsp;#{val}</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">}<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">if</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;head.code</SPAN><SPAN style="COLOR: rgb(0,0,0)">==</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">404"</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">File&nbsp;not&nbsp;Found"</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elsif&nbsp;head.code</SPAN><SPAN style="COLOR: rgb(0,0,0)">==</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">401"</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">print</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">Authorization&nbsp;Required\n&nbsp;User&nbsp;name?"</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gets<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;uname</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">$_.chomp<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">print</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">Password?"</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;gets<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pwd</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">$_.chomp<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unpwd</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">uname&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">:</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">+</SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;pwd<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;unpwd<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hval</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">[unpwd].pack(</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">m</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">)<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;z</SPAN><SPAN style="COLOR: rgb(0,0,0)">=</SPAN><SPAN style="COLOR: rgb(0,0,0)">{</SPAN><SPAN style="COLOR: rgb(0,128,0)">'</SPAN><SPAN style="COLOR: rgb(0,128,0)">Authorization'&nbsp;=&gt;&nbsp;'Basic&nbsp;'&nbsp;+&nbsp;hval}</SPAN><SPAN style="COLOR: rgb(0,128,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;retry<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">end</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;rescue&nbsp;SystemCallError<BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,0)">"</SPAN><SPAN style="COLOR: rgb(0,0,0)">Can't&nbsp;connect"</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,0)">&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: rgb(0,0,255)">end</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: rgb(0,0,255)">end</SPAN><SPAN style="COLOR: rgb(0,0,0)"><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top><BR><IMG src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align=top>fetch(</SPAN><SPAN style="COLOR: rgb(0,128,0)">'</SPAN><SPAN style="COLOR: rgb(0,128,0)">www.blogjava.net',&nbsp;80,&nbsp;'/blake/articles/5471.html')</SPAN></DIV></DIV>
<P><SPAN class=technoratitag>Technorati Tags: <A href="http://www.technorati.com/tags/Ruby" rel=tag>Ruby</A> | <A href="http://www.technorati.com/tags/ROR" rel=tag>ROR</A></SPAN> <A href="http://www.technorati.com/cosmos/search.html?rank=links&amp;url=http://www.blogjava.net/blake/archive/2005/06/02/5476.html"><IMG src="http://www.blogjava.net/images/blogjava_net/blake/Misc/bubble_h17.gif" border=0></A> <A href="http://www.technorati.com/ping.html?url=http://www.blogjava.net/blake/archive/2005/06/02/5476.html"><IMG alt="Ping Technorati" src="http://www.blogjava.net/images/blogjava_net/blake/Misc/refresh.gif" border=0></A></P><img src ="http://www.blogjava.net/Blake/aggbug/5476.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/Blake/" target="_blank">Blake HAN</a> 2005-06-02 16:52 <a href="http://www.blogjava.net/Blake/archive/2005/06/02/5476.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>