<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6084390055539385063</id><updated>2011-04-21T11:48:05.356-07:00</updated><category term='ruby'/><category term='rails view'/><category term='rails controller'/><category term='software'/><category term='rails config'/><category term='rails general'/><category term='rails model'/><category term='rails application'/><category term='database'/><title type='text'>deeply love rubyOnRails</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default?start-index=101&amp;max-results=100'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>104</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3150103118074050843</id><published>2008-06-15T22:02:00.000-07:00</published><updated>2008-06-15T22:04:49.712-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>中文字比較</title><content type='html'>一個中文字利用3byte表示，&lt;div&gt;因此若要比較a="我愛妳"和b="妳愛我"的字首，&lt;/div&gt;&lt;div&gt;要比較  a[0]==b[0] &amp;amp;&amp;amp; a[1]==b[1] &amp;amp;&amp;amp; a[2] == b[2]&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3150103118074050843?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3150103118074050843/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3150103118074050843' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3150103118074050843'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3150103118074050843'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/06/blog-post.html' title='中文字比較'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8011846640722771423</id><published>2008-06-11T10:05:00.000-07:00</published><updated>2008-06-11T10:06:15.080-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>rails API</title><content type='html'>api.rubyonrails.org&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8011846640722771423?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8011846640722771423/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8011846640722771423' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8011846640722771423'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8011846640722771423'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/06/rails-api.html' title='rails API'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5557451821334924787</id><published>2008-06-11T09:43:00.001-07:00</published><updated>2008-06-11T10:01:38.032-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>included  &amp; extend</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;included:&lt;/span&gt;&lt;/div&gt;the method defines the action to do when the class or module get included &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;extend:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;extend the class's ability by including module&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;module M&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Class C&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;c= C.new&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;c.extend(M)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;note:  use object to extend, get instance method, &lt;/div&gt;&lt;div&gt;           use class to extend, get class method&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5557451821334924787?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5557451821334924787/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5557451821334924787' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5557451821334924787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5557451821334924787'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/06/included.html' title='included  &amp; extend'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5391127446397254706</id><published>2008-06-11T09:29:00.000-07:00</published><updated>2008-06-11T09:31:05.789-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>class_eval</title><content type='html'>define method for class&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;A=Class.new&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;A.class_eval do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      def  test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          puts "test"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a=A.new&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a.test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  test&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5391127446397254706?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5391127446397254706/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5391127446397254706' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5391127446397254706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5391127446397254706'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/06/classeval.html' title='class_eval'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5523176443783207907</id><published>2008-06-10T06:28:00.000-07:00</published><updated>2008-06-10T07:12:55.816-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>partial</title><content type='html'>include the view in other file&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;render :partial=&gt; "books"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;render the view in _books.html.erb (  the partial view file must &lt;/div&gt;&lt;div&gt;start with _ )&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;render :partial =&gt; "rabbit/list"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;render the view in different directory&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;note: the variable partial view can access is the variable the master view can access &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5523176443783207907?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5523176443783207907/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5523176443783207907' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5523176443783207907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5523176443783207907'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/06/partial.html' title='partial'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-726467468641995199</id><published>2008-06-08T10:47:00.000-07:00</published><updated>2008-06-08T10:51:38.309-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>self &amp; method</title><content type='html'>when there is a method ending with =,  such as test=, &lt;div&gt;and there is another method  run&lt;/div&gt;&lt;div&gt;In the definition of run, there are two conditions:&lt;/div&gt;&lt;div&gt;(1)  test=3&lt;/div&gt;&lt;div&gt;      this means test is a local variable&lt;/div&gt;&lt;div&gt;(2) self.test=2&lt;/div&gt;&lt;div&gt;      this will call test method with parameter 2&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hence, when calling the method ending with = in the method definition, we can not omit self&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-726467468641995199?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/726467468641995199/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=726467468641995199' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/726467468641995199'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/726467468641995199'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/06/self-method.html' title='self &amp; method'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5012460280668138016</id><published>2008-06-08T10:31:00.000-07:00</published><updated>2008-06-08T10:41:24.647-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails model'/><title type='text'>association</title><content type='html'>&lt;div&gt;use class methods( has_one, belongs_to, has_many,  has_and_belongs_to_many)&lt;/div&gt;&lt;div&gt;to create instance methods&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;has_one &amp;amp; belongs_to&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;has_many &amp;amp; belongs_to&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;has_and_belongs_to_many&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;the parameter for these methods:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;:dependent =&gt; true&lt;/span&gt;&lt;/div&gt;&lt;div&gt;for delete.  &lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class Customer &lt;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;         has_many  :orders,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                             :dependent=&gt;true&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;if the customer A is deleted, its orders are also deleted&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;:order&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;:order=&gt;"created_at ASC"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ascending order according to created_at field&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5012460280668138016?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5012460280668138016/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5012460280668138016' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5012460280668138016'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5012460280668138016'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/06/association.html' title='association'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4168175819675178182</id><published>2008-05-26T10:13:00.000-07:00</published><updated>2008-06-10T22:30:37.517-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>symbol</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;change string to symbol:&lt;/span&gt;&lt;div&gt;use to_sym or intern&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"test".to_sym&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  :test&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;change symbol to string&lt;/span&gt;&lt;/div&gt;&lt;div&gt;method 1: use to_s&lt;/div&gt;&lt;div&gt;method 2: use #{ }&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"#{:abc}"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt; "abc"&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4168175819675178182?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4168175819675178182/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4168175819675178182' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4168175819675178182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4168175819675178182'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/symbol.html' title='symbol'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6435170650913861861</id><published>2008-05-25T03:05:00.000-07:00</published><updated>2008-05-25T03:15:20.972-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>methods</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;methods:&lt;/span&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;A.methods:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;show class methods&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;A.methods(false):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;only show class methods of A, not including inherited methods&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;a.methods:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;show instance methods of a&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;instance_methods:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;A.instance_methods equals a.methods&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;A.instance_methods(false):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;show only instance_methods 0f A, not including inherited methods&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;private_methods, public_methods, protected_methods, singleton_methods&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6435170650913861861?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6435170650913861861/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6435170650913861861' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6435170650913861861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6435170650913861861'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/methods.html' title='methods'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-2301520152589870731</id><published>2008-05-25T02:53:00.000-07:00</published><updated>2008-05-25T03:04:55.528-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>compare: equal?,  Comparable module</title><content type='html'>check  whether  two objects are the same object&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;define how to compare&lt;/span&gt;&lt;/div&gt;&lt;div&gt;use Comparable module &amp;amp; define &lt;=&gt; method&lt;/div&gt;&lt;div&gt;the return value of method &lt;=&gt; ,  1, 0 , &amp;amp; -1 decides greater than, equal than, &amp;amp; less than&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class Rabbit&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     include Comparable &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     attr_accessor  :name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     def  &lt;=&gt; (other_rabbit)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          if  self.name &lt;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                  -1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          elsif  self.name &gt; other_rabbit.name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                  1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                  0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          end &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if the thing to compare know how to compare, there is a shorter definition&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def  &lt;=&gt; (other_rabbit)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;       self.name&lt;=&gt; other_rabbit.name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-2301520152589870731?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/2301520152589870731/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=2301520152589870731' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2301520152589870731'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2301520152589870731'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/compare-equal-comparable-module.html' title='compare: equal?,  Comparable module'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3497533462730854310</id><published>2008-05-25T02:51:00.000-07:00</published><updated>2008-05-25T02:53:07.030-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>true, false &amp; nil</title><content type='html'>In Ruby, nil &amp;amp; false  are the only two objects have boolean value of false&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3497533462730854310?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3497533462730854310/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3497533462730854310' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3497533462730854310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3497533462730854310'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/true-false-nil.html' title='true, false &amp; nil'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5782603787165493173</id><published>2008-05-24T19:40:00.000-07:00</published><updated>2008-05-24T19:50:20.263-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>for, each</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;for&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;for a in [1,2,3]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;puts a&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;each&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;[1,2,3].each do |i|&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;puts i&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5782603787165493173?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5782603787165493173/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5782603787165493173' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5782603787165493173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5782603787165493173'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/for.html' title='for, each'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6617763218452223161</id><published>2008-05-24T19:36:00.000-07:00</published><updated>2008-05-24T19:39:55.437-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>loop, while, until</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;loop&lt;/span&gt;&lt;/div&gt;ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;loop do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    a=a+1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    break if a&gt;3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;loop do &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     a=a+1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     next if a &lt;3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     break&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;while&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;while a&lt;3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;until:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;until a&gt;3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6617763218452223161?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6617763218452223161/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6617763218452223161' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6617763218452223161'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6617763218452223161'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/loop-while-until.html' title='loop, while, until'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7865518564170956712</id><published>2008-05-24T19:31:00.000-07:00</published><updated>2008-05-24T19:36:06.286-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>case</title><content type='html'>ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;case  name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;when "peter"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;puts "peter"&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;when "andy"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;puts  "andy"&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;else&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;puts  "others"&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;how it works&lt;/span&gt;&lt;/div&gt;&lt;div&gt;translate to &lt;/div&gt;&lt;div&gt;if "peter" === name&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;note: the === method can be customarily defined&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7865518564170956712?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7865518564170956712/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7865518564170956712' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7865518564170956712'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7865518564170956712'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/case.html' title='case'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7766368165718026861</id><published>2008-05-24T08:46:00.000-07:00</published><updated>2008-05-24T08:55:31.577-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>private &amp; protected methods</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;private method:&lt;/span&gt;&lt;/div&gt;(1) use private  with argument&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;private  :test,  :run&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;(2) use private&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;private&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def  test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def run &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;the methods after private are private&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;protected method:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;use protected&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;can call the object's protected method as long as self is an instance of the same class  as the object whose protected method is called&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7766368165718026861?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7766368165718026861/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7766368165718026861' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7766368165718026861'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7766368165718026861'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/private-methods.html' title='private &amp; protected methods'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4790993156710456625</id><published>2008-05-24T08:41:00.001-07:00</published><updated>2008-05-24T08:44:54.477-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>global variable</title><content type='html'>start with $&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;built-in global variables:&lt;/div&gt;&lt;div&gt;$: the directories that make up the path Ruby searches for external file&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;$0: name of the file Ruby is executing&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;$$: process id of Ruby process&lt;/div&gt;&lt;div&gt;ps:  use English.rb to replace these built-in global variables with meaningful names&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4790993156710456625?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4790993156710456625/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4790993156710456625' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4790993156710456625'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4790993156710456625'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/global-variable.html' title='global variable'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6470591067665161837</id><published>2008-05-22T22:04:00.000-07:00</published><updated>2008-05-22T22:07:17.912-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>instance variable</title><content type='html'>In the class definition, the instance variable insides method &amp;amp; outside method are not the same&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the instance variable inside method belongs to object&lt;/div&gt;&lt;div&gt;the instance variable outside method belongs to class&lt;span class="Apple-tab-span" style="white-space:pre"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6470591067665161837?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6470591067665161837/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6470591067665161837' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6470591067665161837'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6470591067665161837'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/instance-variable.html' title='instance variable'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5220160652515533491</id><published>2008-05-22T21:47:00.000-07:00</published><updated>2008-05-22T21:50:56.408-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>class &amp; self</title><content type='html'>In the class definition, self = class&lt;div&gt;so Rabbit.run = self.run&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In the class-method definition,  self = class&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5220160652515533491?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5220160652515533491/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5220160652515533491' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5220160652515533491'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5220160652515533491'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/class-self.html' title='class &amp; self'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4936171654873914969</id><published>2008-05-22T21:39:00.000-07:00</published><updated>2008-05-22T21:46:30.250-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>:: access</title><content type='html'>(1) access constant&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(2) access nested class&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;module ActionController&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;       module  Routing&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;              class Route&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;....&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;ActionController::Routing::Route.new&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class  Rabbit &lt;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class ApplicationController &lt;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(3) access nested module&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4936171654873914969?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4936171654873914969/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4936171654873914969' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4936171654873914969'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4936171654873914969'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/access.html' title=':: access'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6605178761078215370</id><published>2008-05-22T21:32:00.000-07:00</published><updated>2008-05-22T21:37:26.848-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>method_missing</title><content type='html'>If the message sent to object is the message object can't understand, it will trigger execution of method_missing&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Rails use method_missing to look up database &amp;amp; create methods &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6605178761078215370?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6605178761078215370/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6605178761078215370' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6605178761078215370'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6605178761078215370'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/methodmissing.html' title='method_missing'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3596383475598130548</id><published>2008-05-20T22:07:00.000-07:00</published><updated>2008-05-20T22:13:34.026-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>super keyword</title><content type='html'>call the method of superclass or module&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class A&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    def test(num)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;           puts "A test #{num}"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class B  &lt;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     def test( num)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;           super&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;   puts "B test #{num}"&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;b= B.new&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;b.test(2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  A test 2&lt;/div&gt;&lt;div&gt;         B  test 2&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;super will pass the parameters to superclass or module&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;another usage:  call super will parameters to pass specific parameters&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3596383475598130548?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3596383475598130548/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3596383475598130548' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3596383475598130548'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3596383475598130548'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/super-keyword.html' title='super keyword'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-1865167269700368879</id><published>2008-05-20T10:03:00.000-07:00</published><updated>2008-05-20T10:04:10.668-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>root module  &amp; root class</title><content type='html'>root class:  Object&lt;div&gt;root module:  Kernel&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-1865167269700368879?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/1865167269700368879/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=1865167269700368879' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1865167269700368879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1865167269700368879'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/root-module-root-class.html' title='root module  &amp; root class'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3592581632963183890</id><published>2008-05-20T09:37:00.000-07:00</published><updated>2008-05-20T09:40:54.974-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>attr_reader,  attr_writer,</title><content type='html'>the getter:&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;attr_reader  :name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the setter:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;attr_writer :name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;getter &amp;amp; setter:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;attr_accessor :name&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3592581632963183890?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3592581632963183890/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3592581632963183890' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3592581632963183890'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3592581632963183890'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/attrreader-attrwriter.html' title='attr_reader,  attr_writer,'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-1942491973623878863</id><published>2008-05-18T07:14:00.000-07:00</published><updated>2008-05-18T07:16:53.938-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>respond_to?</title><content type='html'>check if the object has specific method&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;test.respond_to?("methods")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt; true&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-1942491973623878863?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/1942491973623878863/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=1942491973623878863' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1942491973623878863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1942491973623878863'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/respondto.html' title='respond_to?'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-1652027936727907012</id><published>2008-05-18T07:11:00.000-07:00</published><updated>2008-05-18T07:13:45.215-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>object_id</title><content type='html'>Object's method&lt;div&gt;return the id of the object&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a=3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;b=a&lt;/span&gt;&lt;/div&gt;&lt;div&gt;now a &amp;amp; b have the same object id &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-1652027936727907012?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/1652027936727907012/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=1652027936727907012' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1652027936727907012'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1652027936727907012'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/objectid.html' title='object_id'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5392390327816255821</id><published>2008-05-14T22:02:00.000-07:00</published><updated>2008-05-14T22:11:46.666-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><title type='text'>the data controller can access</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;CGI data:&lt;/span&gt;&lt;div&gt;access @params  via params method&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;params[:id],  params[:user][:age]&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;session information:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;access @session via session method&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;session['user']&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;model's data&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex: &lt;/div&gt;&lt;div&gt;model Car has a name field&lt;/div&gt;&lt;div&gt;car is an instance of model Car&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;car.name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5392390327816255821?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5392390327816255821/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5392390327816255821' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5392390327816255821'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5392390327816255821'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/data-controller-can-access.html' title='the data controller can access'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4019128709934525853</id><published>2008-05-13T03:44:00.000-07:00</published><updated>2008-06-09T22:09:32.100-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='database'/><title type='text'>mysql  command</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;&lt;div&gt;start mySQL:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;sudo /usr/local/mysql/bin mysqld_safe&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;stop mySQL:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;sudo /usr/local/mysql/bin mysqladmin shutdown&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;create an account for a database:&lt;/span&gt;&lt;div&gt;grant  all on *.*  to 'deeplove'@'localhost'  identified by  '111';&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;create new user account "deeplove", with password 111, &lt;/div&gt;&lt;div&gt;connect to database from "localhost", all  means you can do anything( SELECT, INSERT, ...)&lt;/div&gt;&lt;div&gt;*.* means you can connect to every database ( Dog.* means you can only connect to Dog database)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;join:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;collect information from two or more tables &amp;amp; present it as a single table&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;left join  ...  on ...  :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;return all matching rows from first table, even if there are no matching rows in the second table&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;group by&lt;/span&gt;&lt;/div&gt;&lt;div&gt;combine two tables using the filed both tables have &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;select syntax&lt;/span&gt;&lt;/div&gt;&lt;div&gt;select columns from table where condition&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4019128709934525853?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4019128709934525853/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4019128709934525853' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4019128709934525853'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4019128709934525853'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/mysql-command.html' title='mysql  command'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7170850971099105708</id><published>2008-05-12T10:50:00.000-07:00</published><updated>2008-05-12T22:24:38.550-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>rails source code location in  mac</title><content type='html'>/Library/Ruby/Gems/1.8/gems/rails-2.0.2&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;/Library/Ruby/Gems/1.8/gems/actionpack-2.0.2/lib&lt;/div&gt;&lt;div&gt;action_controller.rb &amp;amp; action_view.rb are in this folder&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;/Library/Ruby/Gems/1.8/gems/activerecord-2.0.2&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7170850971099105708?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7170850971099105708/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7170850971099105708' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7170850971099105708'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7170850971099105708'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/rails-source-code-location-in-mac.html' title='rails source code location in  mac'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7724988169702541915</id><published>2008-05-12T10:03:00.000-07:00</published><updated>2008-05-12T10:04:32.197-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>require vs load</title><content type='html'>ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;require  'test'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;require  'tes&lt;/span&gt;t'&lt;/div&gt;&lt;div&gt;second require is useless&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;load  'test'&lt;/div&gt;&lt;div&gt;load  'test'&lt;/div&gt;&lt;div&gt;second load will load test again &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7724988169702541915?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7724988169702541915/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7724988169702541915' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7724988169702541915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7724988169702541915'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/require-vs-load.html' title='require vs load'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8847580254279550501</id><published>2008-05-12T08:54:00.000-07:00</published><updated>2008-05-12T08:55:22.096-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>puts and print</title><content type='html'>puts will print new line&lt;div&gt;print will not&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8847580254279550501?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8847580254279550501/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8847580254279550501' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8847580254279550501'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8847580254279550501'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/puts-and-print.html' title='puts and print'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6655715053380230759</id><published>2008-05-12T08:35:00.000-07:00</published><updated>2008-05-12T09:03:28.309-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>gets</title><content type='html'>get a line of input( in string)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6655715053380230759?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6655715053380230759/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6655715053380230759' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6655715053380230759'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6655715053380230759'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/gets.html' title='gets'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4028853754041361650</id><published>2008-05-12T03:53:00.000-07:00</published><updated>2008-05-12T04:02:16.609-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>paginate</title><content type='html'>divide large collections into pages&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;in the controller:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def  car_list&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     @car_pages,  @cars = paginate ( :cars,  :order_by =&gt; 'name')&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;@car_pages is a paginator object.&lt;/div&gt;&lt;div&gt;@cars contain 10 rows.  ( default is 10 rows)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;in the view:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;table&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  for car in @cars&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;       tr  td  car.name  td  tr&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;table&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;hr&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;   pagination_links(@car_pages) &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;hr&lt;/span&gt;&lt;/div&gt;&lt;div&gt;pagination_links  show the current page, two page numbers on either side of current page, first page &amp;amp; last page &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4028853754041361650?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4028853754041361650/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4028853754041361650' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4028853754041361650'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4028853754041361650'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/paginate.html' title='paginate'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6289799772160937816</id><published>2008-05-11T07:32:00.000-07:00</published><updated>2008-06-10T06:27:08.462-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>helper</title><content type='html'>remove the logic from view to helper&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;module   TestHelper&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;              def  run&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                       "test_title"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;              end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;in the test controller&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;%=  run  %&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;originally the function in the helper file can only be accessed by related view,&lt;/div&gt;&lt;div&gt;but there is method for sharing helper&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;sharing helper:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;method 1:&lt;/div&gt;&lt;div&gt;define the method in application_helper.rb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;method  2:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;add  TestHelper  to controller&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;helper  :test&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6289799772160937816?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6289799772160937816/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6289799772160937816' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6289799772160937816'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6289799772160937816'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/helper.html' title='helper'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7933893756368277813</id><published>2008-05-11T07:14:00.000-07:00</published><updated>2008-05-11T07:23:37.440-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>h( )</title><content type='html'>escape html tag&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;%= "&amp;lt;b&gt;test&amp;lt;/b&gt;"% &gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;show test in bold&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;%= h("&amp;lt;b&gt;test&amp;lt;/b&gt;") %&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;show  &amp;lt;b%&gt;test&amp;lt;/b&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7933893756368277813?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7933893756368277813/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7933893756368277813' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7933893756368277813'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7933893756368277813'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/h.html' title='h( )'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3798954807138230080</id><published>2008-05-11T06:40:00.000-07:00</published><updated>2008-05-11T06:43:10.970-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>xml template</title><content type='html'>&lt;div&gt;builder template:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;xml builder:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;xml.tagName&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;xml.productName ( "car")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt;   &amp;lt;productName&amp;gt;car&amp;lt;/productName&amp;gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3798954807138230080?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3798954807138230080/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3798954807138230080' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3798954807138230080'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3798954807138230080'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/xml-template.html' title='xml template'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3699182035436125998</id><published>2008-05-11T04:53:00.000-07:00</published><updated>2008-05-11T05:31:03.036-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>cache</title><content type='html'>the page is cached .&lt;div&gt;Hence,  after first request, the same URL's response is deliver from cache, rails is no involved &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;3 caches:&lt;/div&gt;&lt;div&gt;page caching,  action caching  &amp;amp; fragment caching&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;page caching:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;caches_page  :test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;action caching:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;execute filter before return cached pages&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;before_filter  :test_filter&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;caches_action  :test2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;turn on caching( in environment.rb) :&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;ActionController::Base.perform_caching = true&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;removing cache:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;expire_page&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;expire_page  :action=&gt;test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;expire_action:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;expire_action :action=&gt;test2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;sweeper:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;observe the model. When the model is changed, the sweeper expire the cached pages that &lt;/div&gt;&lt;div&gt;depend on the model&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;in app/models&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class  TestSweeper &lt;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;         observe  Car&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;         def  after_create(car)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                   expire_car_page&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;         end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;in app/controllers&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class Test &lt;&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    cache_sweeper  :test_sweeper&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;span class="Apple-tab-span" style="white-space:pre"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;the location to store cached pages:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;http://localhost:3000/content/show/1  is stored in app/public/content/show/1.html&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3699182035436125998?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3699182035436125998/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3699182035436125998' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3699182035436125998'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3699182035436125998'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/cache.html' title='cache'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4291604022244146811</id><published>2008-05-11T04:39:00.000-07:00</published><updated>2008-05-11T04:51:26.439-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><title type='text'>verification</title><content type='html'>verify that certain conditions are met&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;verify:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;verify   :session =&gt; :user_id,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;             :add_flash =&gt; { :note=&gt; "you are wrong" }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;             :redirect_to =&gt; index&lt;/span&gt;&lt;/div&gt;&lt;div&gt;if the session does not contain key :user_id,  &lt;/div&gt;&lt;div&gt;a note is added to flash &amp;amp; request is redirected to index&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4291604022244146811?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4291604022244146811/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4291604022244146811' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4291604022244146811'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4291604022244146811'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/verification.html' title='verification'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-170814417254313818</id><published>2008-05-10T19:31:00.000-07:00</published><updated>2008-05-10T19:38:43.600-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>redirect_to</title><content type='html'>three forms:&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;1. redirect_to ( options ... )&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;redirect_to (:action=&gt;jump)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. redirect_to (path)&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;redirect_to ("/test/run")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;show /view/test/run.html.erb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;3. redirect_to( url)&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;redirect_to("http://www.google.com")&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-170814417254313818?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/170814417254313818/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=170814417254313818' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/170814417254313818'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/170814417254313818'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/redirectto.html' title='redirect_to'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-2262032098190763112</id><published>2008-05-10T08:27:00.000-07:00</published><updated>2008-05-10T08:30:14.459-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>logger</title><content type='html'>4 levels:&lt;div&gt;warn,  info,  error,  fatal&lt;/div&gt;&lt;div&gt;ex&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;logger.warn("invalid number")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;log file:&lt;/div&gt;&lt;div&gt;/log/development.log,  /log/test.log,  /log/production.log&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-2262032098190763112?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/2262032098190763112/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=2262032098190763112' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2262032098190763112'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2262032098190763112'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/logger.html' title='logger'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3334571157707572780</id><published>2008-05-10T07:46:00.000-07:00</published><updated>2008-05-10T07:58:09.357-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><title type='text'>group controllers into module</title><content type='html'>For example,  two directories  Test1  &amp;amp; Test2, &lt;br /&gt;controller Rabbit1Controller in Test1,  Rabbit2Controller in Test2&lt;br /&gt;&lt;br /&gt;url_for( :controller=&gt; "rabbit1", :action=&gt;"jump")&lt;br /&gt;---&gt;  http://localhost:3000/test1/rabbit1/jump&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3334571157707572780?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3334571157707572780/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3334571157707572780' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3334571157707572780'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3334571157707572780'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/group-controllers-into-module.html' title='group controllers into module'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3676990912279179014</id><published>2008-05-08T22:23:00.000-07:00</published><updated>2008-05-08T22:30:56.077-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>rails program load sequence</title><content type='html'>ex:  http://localhost:3000/rabbit/list&lt;div&gt;when getting request above, the load sequence is as follows:&lt;/div&gt;&lt;div&gt;1. load rabbit_controller.rb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2. instantiate an object of class RabbitController&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;3. look in app/helpers for rabbit_helper.rb.&lt;/div&gt;&lt;div&gt;    If found, the module RabbitHelper is mixed into RabbitController&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;4 look in app/models for rabbit.rb. If found, load it&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;define the models used in controller:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;model  :car,  :clothes&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;define the observers used in controller:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;observer   :car_observer&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;define the model used in controller&lt;span class="Apple-style-span"  style=" ;font-size:49px;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3676990912279179014?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3676990912279179014/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3676990912279179014' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3676990912279179014'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3676990912279179014'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/rails-program-load-sequence.html' title='rails program load sequence'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7061664168451806864</id><published>2008-05-08T22:16:00.003-07:00</published><updated>2008-05-11T04:24:40.986-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>flash</title><content type='html'>the value stored in the flash in the first request is available in the second request.&lt;div&gt;After processing 2nd request, the value is removed from flash&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;main use:&lt;/div&gt;&lt;div&gt;error message&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def  test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    flash[:note] = "error"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    redirect_to :action=&gt;test2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;test2.html.erb&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;%= @flash[:note] %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7061664168451806864?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7061664168451806864/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7061664168451806864' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7061664168451806864'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7061664168451806864'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/flash.html' title='flash'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7114047341617143041</id><published>2008-05-08T22:16:00.001-07:00</published><updated>2008-05-08T22:16:31.203-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><title type='text'>session &amp; cookie</title><content type='html'>&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7114047341617143041?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7114047341617143041/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7114047341617143041' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7114047341617143041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7114047341617143041'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/session-cookie.html' title='session &amp; cookie'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8576536543118953330</id><published>2008-05-08T22:03:00.000-07:00</published><updated>2008-06-10T09:59:38.275-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>controller action, view tempelate, render</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;controller裡定義的action(method)會對應到view下的templelate&lt;/span&gt;&lt;/div&gt;&lt;div&gt;例如index對應到index.html.erb&lt;/div&gt;&lt;div&gt;所以如果controller要做的action是index，&lt;/div&gt;&lt;div&gt;browser顯示的網頁即是index.html.erb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;為何action是index，即顯示index.html.erb ?&lt;/span&gt;&lt;/div&gt;&lt;div&gt;一般在controller定義的action，&lt;/div&gt;&lt;div&gt;例如index，&lt;/div&gt;&lt;div&gt;預設都會呼叫如下的render 指令，&lt;/div&gt;&lt;div&gt;所以controller在做index action時，&lt;/div&gt;&lt;div&gt;即會顯示index.html.erb&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;render command:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;render :template =&gt; “test/index”&lt;/span&gt;&lt;/div&gt;&lt;div&gt;顯示 view/test/index.html.erb&lt;/div&gt;&lt;div&gt;&lt;div&gt;:template後接的path是相對於view&lt;/div&gt;&lt;div&gt;如果改成:file，之後的path是絕對路徑&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;如果render顯示的是另一個page，&lt;/div&gt;&lt;div&gt;改變的是顯示的內容，&lt;/div&gt;&lt;div&gt;URL還是原page的URL，&lt;/div&gt;&lt;div&gt;若要連URL一起改變，&lt;/div&gt;&lt;div&gt;要代用redirect_to&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;render  :action=&gt;”index”&lt;/span&gt;&lt;/div&gt;&lt;div&gt;顯示 index.html.erb&lt;/div&gt;&lt;div&gt;(注意render不會做action，只會顯示頁面，&lt;/div&gt;&lt;div&gt;若要做action，要用redirect_to) &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;render :text=&gt; “hello”&lt;/span&gt;&lt;/div&gt;&lt;div&gt;顯示hello&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;:status&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;render  :status=&gt;404&lt;/span&gt;&lt;/div&gt;&lt;div&gt;html response的status&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;可以不定義action，但一定要定義顯示的頁面&lt;/div&gt;&lt;div&gt;例如index action沒定義，&lt;/div&gt;&lt;div&gt;但index.html.erb有定義，&lt;/div&gt;&lt;div&gt;則browser還是可以顯示正確的頁面。&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the instance variable of the controller is available in the template&lt;/div&gt;&lt;div&gt;the template can access instance variable set in the controller action. Hence, rabbit's view can access dog's controller's instance variable if it is triggered from dog's action&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8576536543118953330?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8576536543118953330/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8576536543118953330' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8576536543118953330'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8576536543118953330'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/controller-action-view-tempelate-render.html' title='controller action, view tempelate, render'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-785282538517011726</id><published>2008-05-08T11:35:00.000-07:00</published><updated>2008-05-20T10:00:04.734-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>form helper</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;form_tag:   和model無關&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;% form_tag do %&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;p&amp;gt;&amp;lt;label for=”login”&amp;gt;Login&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;%= text_field_tag  ‘login’ %&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;p&amp;gt;&amp;lt;%= submit_tag ‘Log in’ %&amp;gt; &amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;% end %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;1.如果form_tag後沒有接action，那麼action就是form目前所在的&lt;/div&gt;&lt;div&gt;  頁面對應到的method&lt;/div&gt;&lt;div&gt;2存取使用者輸入的資料，例如param, such as params[:login], log對應&lt;/div&gt;&lt;div&gt;  到text_filed_tag的值&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); "&gt;&amp;lt;% form_tag  :action=&gt;'play'  do %&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); "&gt;&amp;lt;p&amp;gt;&amp;lt;label for=”login”&amp;gt;Login&amp;lt;/label&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); "&gt;&amp;lt;%= text_field_tag  'car',  ‘login’ %&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); "&gt;&amp;lt;p&amp;gt;&amp;lt;%= submit_tag ‘Log in’ %&amp;gt; &amp;lt;/p&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); "&gt;&amp;lt;% end %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;1. text_field_tag後接的car是model name，login是car的attribute&lt;/div&gt;&lt;div&gt;   , the controller can access it using  params[:car][:login]&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;submit_tag 後接的字串是submit button上的文字&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;form_for : 和model有關&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt; &lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;% form_for :person, @person, &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    :url =&gt; { :action =&gt; "create" } do |f| %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      &amp;lt;%= f.text_field :first_name %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      &amp;lt;%= f.text_field :last_name %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      &amp;lt;%= submit_tag 'Create' %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  &amp;lt;% end %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;對應的html&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; &amp;lt;form action="/persons/create" method="post"&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      &amp;lt;input id="person_first_name" name="person[first_name]" size="30" type="text" /&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      &amp;lt;input id="person_last_name" name="person[last_name]" size="30" type="text" /&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    &amp;lt;input name="commit" type="submit" value="Create" /&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    &amp;lt;/form&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;存取使用者輸入的資料:&lt;/div&gt;&lt;div&gt;以上面為例子，Person.new(params[:person] )&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;% form_for :rabbit ,  url=&gt;{ :controller=&gt;:rabbit, :action=&gt;create},&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;      :html=&gt; {:id=&gt;’peter’ } do |t| %&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;對應的html&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&amp;lt;form action="/rabbit/create" id="peter" method="post"&amp;gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;text_field &amp;amp; text_field_tag&lt;/span&gt;&lt;/div&gt;&lt;div&gt;regular form helper is usually end with tag&lt;/div&gt;&lt;div&gt;model form helper is usually not end with tag &lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;text_field :customer, :name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;create customer in the action of controller:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;@customer = Customer.new(params[:customer])&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;text_field:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;hidden_field:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;password_field:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;text_area:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;radio_button(:variable, :attribute,  tag_value,  options):&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;check_box:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;select:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;selection list&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-785282538517011726?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/785282538517011726/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=785282538517011726' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/785282538517011726'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/785282538517011726'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/form-helper.html' title='form helper'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5700708011986312350</id><published>2008-05-08T11:30:00.000-07:00</published><updated>2008-05-08T11:31:34.308-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><title type='text'>save &amp; save!</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;save object into database&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;save! will raise a exception if the save is not successful &lt;/div&gt;&lt;div&gt;save only return false when save is not successful &lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5700708011986312350?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5700708011986312350/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5700708011986312350' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5700708011986312350'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5700708011986312350'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/save-save.html' title='save &amp; save!'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-779885942545727991</id><published>2008-05-08T11:16:00.000-07:00</published><updated>2008-05-25T02:44:55.813-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails model'/><title type='text'>update_attributes, updat &amp; update_all, save</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;update column of table&lt;/span&gt;&lt;div&gt;update will change the state of object and database&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;update_attributes&lt;br /&gt;&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rabbit.update_attributes( :name=&gt; "peter",  :age=&gt; 13)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;update&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Rabbit.update( 5, :name=&gt;"peter", :age=&gt;13)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;update rabbit with id =5&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;update_all:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Rabbit.update_all(:name=&gt;"peter")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;all rabbits' names become "peter"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;use save:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rabbit.name="peter"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rabbit.save&lt;/span&gt;&lt;/div&gt;&lt;div&gt;use save to update database&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-779885942545727991?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/779885942545727991/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=779885942545727991' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/779885942545727991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/779885942545727991'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/updateattributes-updat-updateall.html' title='update_attributes, updat &amp; update_all, save'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6651037711874723152</id><published>2008-05-07T22:01:00.000-07:00</published><updated>2008-06-09T22:13:57.232-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>find method in rails</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;without dynamic find_by_all&lt;/span&gt;&lt;br /&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;@task = Task.find( :all, :conditions=&gt; [‘complete= ?’ ,false] )&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;with dynamic find_by_all&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;@task = Task.find_all_by_complete(false)&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;without dynamic find_by&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;@task = Task.find( :first, :conditions=&gt; [‘complete= ?’ ,false],&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;                                :order=&gt;’created_at DESC’ )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;with dynamic find_by&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;@task = Task.find_by_complete(false,   :order=&gt;’created_at DESC’)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;find by id&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;find( params[:id], :conditions=&gt;[“name=?”, “peter” ] )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;find through association&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;project has many tasks&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;task belongs to project&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;without association:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;@task = Task.find(:all, :conditions=&gt; [ ‘proect_id=? AND complete =?’  , @project_id,  false] )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;with association:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;@project = Project.find(params[:id])&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;@task = @project.tasks.find(:all,     :conditions=&gt;[‘complete=?’,   false])&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;or&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;@task = @project.tasks.find_all_by_complete(false) &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;find method in model&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;將find method定義在model比較好&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;Task的model&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;def  self.find_incompletet &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;    find_all_by_complete(false, :order=&gt;’created_at DESC’ )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;end    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt; 注意: 此find method要定義成class method&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;          到時候可呼叫 @project.tasks.find_incomplete&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;          若定義成instance method，則會error&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;find_by_sql:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;use sql syntax in the find_by_sql&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;pros:  faster&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6651037711874723152?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6651037711874723152/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6651037711874723152' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6651037711874723152'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6651037711874723152'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/find-method-in-rails.html' title='find method in rails'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6368624395514761706</id><published>2008-05-07T08:03:00.000-07:00</published><updated>2008-05-07T10:23:13.462-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails application'/><title type='text'>ActionMailer &amp; gmail</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;use ActionMailer to send email ( with gmail)&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;require 'rubygems' &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;require 'action_mailer' &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;require 'smtp_tls'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class Emailer &lt;&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  def test_email(email_address, email_body) &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    recipients(email_address) &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    from "peter@gmail.com" &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    subject "This is a test e-mail" &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    body email_body &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  end &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;ActionMailer::Base.smtp_settings = { &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  :address =&gt; "smtp.gmail.com", &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  #25 ,465&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  :port =&gt; 587, &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  #:domain =&gt; "localhost.localdomain",&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  :authentication =&gt; :plain, &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  :user_name =&gt; "peter", &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;  :password =&gt; "xxxxxx", &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Emailer.deliver_test_email('jack@yahoo.com', 'this is a test email')&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0);"&gt;smtp_tls is for sending email from gmail&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;send by gmail in rails:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;1. add smtp_tls.rb in configure directory&lt;/div&gt;&lt;div&gt;2. add  require 'smtp_tls'  in environment.rb&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6368624395514761706?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6368624395514761706/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6368624395514761706' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6368624395514761706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6368624395514761706'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/actionmailer-gmail.html' title='ActionMailer &amp; gmail'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3041862585525299310</id><published>2008-05-07T07:37:00.000-07:00</published><updated>2008-05-07T07:38:52.180-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails model'/><title type='text'>access table's column in the model</title><content type='html'>ex:&lt;div&gt;the table rabbits has column  &lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;the model  rabbit can access name by  &lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;self.name&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3041862585525299310?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3041862585525299310/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3041862585525299310' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3041862585525299310'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3041862585525299310'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/access-tables-column-in-model.html' title='access table&apos;s column in the model'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5948417596289612159</id><published>2008-05-07T07:28:00.000-07:00</published><updated>2008-06-08T10:43:02.294-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails model'/><title type='text'>before_create</title><content type='html'>like before_filter,  but before_create is used in the model&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;is executed when the record is created&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5948417596289612159?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5948417596289612159/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5948417596289612159' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5948417596289612159'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5948417596289612159'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/beforecreate.html' title='before_create'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-539494990260219730</id><published>2008-05-07T07:05:00.000-07:00</published><updated>2008-05-11T04:39:05.382-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><title type='text'>filter</title><content type='html'>define the actions to do before(after) some actions&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;two define syntaxes:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;1. use method to define filter&lt;/div&gt;&lt;div&gt;2. use class to define filter&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;before_filter:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;define the actions to do before some actions&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;before_filter :check&lt;/div&gt;&lt;div&gt;do check before any action. &lt;/div&gt;&lt;div&gt;If check return false,  the action is not done&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;after_filter:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;define the actions to do after some actions&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;filter &amp;amp; inheritance :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;B extends A, then A's filter is done first, then B's filter is done&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;filter's scope:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;only for some actions:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;before_filter :check,  :only=&gt;:index&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;before_filter :check,  :only=&gt;[:index,  :new]&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;not for some actions:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;before_filter :check,  :except=&gt;:index&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;around_filter:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;the combination of before_filter &amp;amp; after_filter&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;class TestFilter&lt;/div&gt;&lt;div&gt;    def  before(controller)&lt;/div&gt;&lt;div&gt;         @name="peter"&lt;/div&gt;&lt;div&gt;    end&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;    def  after(controller)&lt;/div&gt;&lt;div&gt;         @name ="andy"&lt;/div&gt;&lt;div&gt;    end&lt;/div&gt;&lt;div&gt;end&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;around filter  TestFilter.new&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-539494990260219730?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/539494990260219730/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=539494990260219730' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/539494990260219730'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/539494990260219730'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/filter.html' title='filter'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-866178365866744798</id><published>2008-05-06T22:10:00.000-07:00</published><updated>2008-05-06T22:14:27.063-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>mongrel</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;a web server &lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;faster than WEBrick&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;install:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;sudo gem install mongrel&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;start:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;mongrel_rails  start&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;start options:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;-d:  run in background &lt;/div&gt;&lt;div&gt;-e:  rails environment to run&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;stop:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;mongrel_rails stop&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;restart:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;mongrel_rails restart&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-866178365866744798?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/866178365866744798/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=866178365866744798' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/866178365866744798'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/866178365866744798'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/mongrel.html' title='mongrel'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8801048667439904778</id><published>2008-05-06T21:55:00.000-07:00</published><updated>2008-05-10T07:38:08.793-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails controller'/><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>link</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;link to css&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;stylesheet_link_tag   'test'&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0);"&gt;test.css is in /public /stylesheets&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;link to image&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;image_tag  'test.jpg'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;test.jpg is in  /public/images&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;link to page&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;link_to  "go to" ,  :controller=&gt;"test", :action=&gt;"index"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;link to javascript:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;javascript_indclude_tag  :defaults&lt;/span&gt;&lt;/div&gt;&lt;div&gt;link to prototype, effects, dragdrop, controls, application in /public/javascripts&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;url_for:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;generate url according to route.rb&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;url_for ( :controller=&gt;"rabbit", :action=&gt;jump )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt;  http://localhost:3000/rabbit/jump &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8801048667439904778?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8801048667439904778/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8801048667439904778' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8801048667439904778'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8801048667439904778'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/link-to-css.html' title='link'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3086373286400464374</id><published>2008-05-06T21:54:00.001-07:00</published><updated>2008-05-14T22:23:45.756-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails view'/><title type='text'>layout</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;the layout for all website:&lt;/div&gt;&lt;div&gt;method 1:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;use application.html.erb, it is the layout for all website&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;method 2:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;define the layout test.html.erb&lt;/div&gt;&lt;div&gt;add following line to app/controllers/application.rb&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;layout "test"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;yield:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;render the template.  The template is rendered at this location within layout&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;layout can access variable defined in the template &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3086373286400464374?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3086373286400464374/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3086373286400464374' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3086373286400464374'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3086373286400464374'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/layout.html' title='layout'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6178865309772303447</id><published>2008-05-06T21:48:00.000-07:00</published><updated>2008-05-10T08:18:00.390-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails config'/><title type='text'>rails routing</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;config/route.rb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;set the page of webSite root:&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;map.root  :controller =&gt; "test"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;note: remember to remove  /public/index.html&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;default route&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;map.connect  ':controller/:action/:id'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;map.connect  ':controller/:action/:id.:format'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex: &lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;http://localhost:3000/test/apple/3.xml&lt;/span&gt;&lt;/div&gt;&lt;div&gt;test map to :controller,  apple map to :action, 3 map to :id, xml map to :format&lt;/div&gt;&lt;div&gt;the parameter get from default route:&lt;/div&gt;&lt;div&gt;params[:controller],  params[:action],  params[:id]&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;set controller &amp;amp; action:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;map.connect  'test/:var',  :controller=&gt;rabbit,  :action=&gt;jump&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;ex: &lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); "&gt;http://localhost:3000/test/apple&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;apple map to :var&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;:requirements&lt;/span&gt;&lt;/div&gt;&lt;div&gt;set the requirement the component must match&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;map.connect  ":day",  :requirements =&gt; { :day =&gt; /[0-3]?\d }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;the pattern for remaining components in the URL ( not specify in the URL)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;use * with a name&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;map.connect  "*anything",  :action=&gt; "unknown_action"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;named route:&lt;/div&gt;&lt;div&gt;replace map.connect with map.routeName,&lt;/div&gt;&lt;div&gt;replace  url_for with routeName_url&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt; &lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;map.run  :controller=&gt;"test", :action=&gt;"run"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; redirect_to (run_url)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt; link_to(" run" , run_url )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6178865309772303447?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6178865309772303447/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6178865309772303447' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6178865309772303447'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6178865309772303447'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/rails-routing.html' title='rails routing'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-2178363140718543500</id><published>2008-05-06T21:39:00.000-07:00</published><updated>2008-05-14T22:26:09.752-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>generate command,  rails command,  rake command, console</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;rails:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rails -d mysql  test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;create files for rails project, using mysql  &lt;/div&gt;&lt;div&gt;( default is sqlite)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;generate:&lt;/span&gt;&lt;/div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;script/generate  controller rabbit index &lt;/span&gt;&lt;div&gt;create rabbit controller with index action,  rabbit test, rabbit helper  &amp;amp; index template in the rabbit view&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;rake:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rake db:migrate&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;create the table in the database based on the migration file&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;script/console:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;-s:  Any modifications you make will be rolled back on exit&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-2178363140718543500?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/2178363140718543500/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=2178363140718543500' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2178363140718543500'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2178363140718543500'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/generate-command-rails-command.html' title='generate command,  rails command,  rake command, console'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3242408955795094398</id><published>2008-05-06T08:40:00.000-07:00</published><updated>2008-05-12T11:28:17.593-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>erube</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;deal with the file includes html &amp;amp; ruby code&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;install:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;get eruby from &lt;a href="http://www.modruby.org/en/index.rbx/eruby/download.html"&gt; http://www.modruby.org/en/index.rbx/eruby/download.html&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;set link:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="  ;font-family:'-webkit-monospace';font-size:15px;"&gt;sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/eruby /usr/local/bin/eruby&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style=" ;font-family:-webkit-monospace;font-size:48px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:'-webkit-monospace';"&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;combine apache &amp;amp; erube:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" font-weight: bold;font-family:-webkit-monospace;"&gt;set link:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="color: rgb(85, 85, 85);   font-family:-webkit-monospace;font-size:15px;"&gt;     ln -s /usr/local/bin/eruby /Library/WebServer/CGI-Executables/eruby&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" font-weight: bold;font-family:-webkit-monospace;"&gt;edit /etc/apache2/httpd.conf&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" font-weight: bold;font-family:-webkit-monospace;"&gt;(1) red part&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" font-weight: bold;font-family:-webkit-monospace;"&gt;&lt;span class="Apple-style-span"  style="color: rgb(85, 85, 85);  font-weight: normal; font-size:15px;"&gt;    &lt;directory&gt;&lt;br /&gt;    AllowOverride None&lt;/directory&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" font-weight: bold;font-family:-webkit-monospace;"&gt;&lt;span class="Apple-style-span"  style="color: rgb(85, 85, 85);  font-weight: normal; font-size:15px;"&gt;    Options &lt;/span&gt;&lt;span class="Apple-style-span"  style=" font-weight: normal; font-size:15px;"&gt;&lt;span class="Apple-style-span" style="color: rgb(255, 0, 0);"&gt;FollowSymLinks&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" font-weight: bold; font-family:-webkit-monospace;"&gt;(2) add following to &lt;/span&gt;&lt;span class="Apple-style-span"   style="  font-style: italic; line-height: 23px; font-family:Verdana;font-size:18px;"&gt;&lt;ifmodule&gt;&lt;/ifmodule&gt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="color: rgb(68, 68, 68);   font-style: italic; line-height: 23px;font-family:Verdana;font-size:18px;"&gt;&lt;span class="Apple-style-span"   style="color: rgb(85, 85, 85);   font-style: normal; line-height: normal; font-family:-webkit-monospace;font-size:15px;"&gt;    AddHandler rubypage .erb .rhtml&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="color: rgb(68, 68, 68);   font-style: italic; line-height: 23px;font-family:Verdana;font-size:18px;"&gt;&lt;span class="Apple-style-span"   style="color: rgb(85, 85, 85);   font-style: normal; line-height: normal; font-family:-webkit-monospace;font-size:15px;"&gt;    Action rubypage /cgi-bin/eruby&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="color: rgb(85, 85, 85);  font-family:-webkit-monospace;font-size:48px;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(85, 85, 85); "&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;run eruby&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span"  style="color: rgb(85, 85, 85);  font-family:'-webkit-monospace';"&gt;&lt;span class="Apple-style-span"  style="font-size:medium;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;:&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style="color: rgb(85, 85, 85);  font-family:'-webkit-monospace';"&gt;eruby  test.html.erb&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"   style="color: rgb(85, 85, 85);  font-family:-webkit-monospace;font-size:48px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(85, 85, 85); font-family: '-webkit-monospace'; "&gt;&lt;span class="Apple-style-span" style="font-size: medium;"&gt;erb&lt;/span&gt;&lt;/span&gt;&lt;span class="Apple-style-span" style="color: rgb(85, 85, 85); font-family: -webkit-monospace; font-size: 48px;"&gt; &lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3242408955795094398?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3242408955795094398/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3242408955795094398' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3242408955795094398'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3242408955795094398'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/modruby.html' title='erube'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8476948776366256616</id><published>2008-05-06T07:06:00.000-07:00</published><updated>2008-05-06T07:27:01.802-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>cgi</title><content type='html'>require 'cgi'&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;cgi's method name equals the tag it create&lt;/div&gt;&lt;div&gt;Hence, cgi.h1 create h1 tag&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;use + to combine the same level tag&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;cgi = CGI.new('html4')&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;cgi.out do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    cgi.html do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          cgi.head  do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                 "test head"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          end  +&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          cgi.body do&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;                cgi.h1 {  "hello" } &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;          end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;---&gt;&lt;/div&gt;&lt;div&gt;&amp;lt;HTML&amp;gt;&amp;lt;HEAD&amp;gt;test head &amp;lt;/HEAD&amp;gt;&amp;lt;BODY&amp;gt;&amp;lt;H1&amp;gt;hello&amp;lt;/H1&amp;gt;&amp;lt;/BODY&amp;gt;&amp;lt;/HTML&amp;gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;cgi.params:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;represent query string&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;http://localhost/cig-bin/test.cgi?name=peter&amp;amp;age=3&lt;/div&gt;&lt;div&gt;cgi.params =  { 'name'=&gt;'peter',   'age'=&gt;'3' }&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8476948776366256616?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8476948776366256616/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8476948776366256616' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8476948776366256616'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8476948776366256616'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/cgi.html' title='cgi'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-404619024908598941</id><published>2008-05-05T21:47:00.000-07:00</published><updated>2008-05-18T07:18:07.576-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>send</title><content type='html'>dynamically call a method with unknown name&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def  test_rabbit(name)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;       puts name&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a="rabbit"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;send("test_#{a}", "peter")&lt;/span&gt;&lt;/div&gt;&lt;div&gt;----&gt;  peter&lt;/div&gt;&lt;div&gt;1st parameter is method name,  second parameter is parameter&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;usage: get method from user input&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;note:&lt;/div&gt;&lt;div&gt;some_object.send(  function_name,  args )  is the same as &lt;/div&gt;&lt;div&gt;some_object.function_name(args )&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-404619024908598941?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/404619024908598941/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=404619024908598941' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/404619024908598941'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/404619024908598941'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/send.html' title='send'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7908041911048027931</id><published>2008-05-04T08:37:00.000-07:00</published><updated>2008-05-05T09:14:19.579-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>show message with debug</title><content type='html'>&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;write to stand error&lt;/span&gt;&lt;/div&gt;ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;warn "error"  if ($DEBUG)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;enable $DEBUG&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ruby -d &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7908041911048027931?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7908041911048027931/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7908041911048027931' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7908041911048027931'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7908041911048027931'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/show-message-with-debug.html' title='show message with debug'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8009488688802271439</id><published>2008-05-04T07:30:00.000-07:00</published><updated>2008-05-04T07:32:26.928-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>xml library</title><content type='html'>require 'rexml/document'&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8009488688802271439?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8009488688802271439/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8009488688802271439' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8009488688802271439'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8009488688802271439'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/xml-library.html' title='xml library'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5344282237011711696</id><published>2008-05-04T02:56:00.001-07:00</published><updated>2008-05-04T02:57:44.679-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>&lt;=&gt;</title><content type='html'>ex:&lt;div&gt;3 &lt;=&gt; 3&lt;/div&gt;&lt;div&gt;---&gt;  0&lt;/div&gt;&lt;div&gt;3 &lt;=&gt; 4&lt;/div&gt;&lt;div&gt;---&gt; -1&lt;/div&gt;&lt;div&gt;4 &lt;=&gt; 3&lt;/div&gt;&lt;div&gt;---&gt;  1&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5344282237011711696?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5344282237011711696/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5344282237011711696' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5344282237011711696'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5344282237011711696'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/ex-3-3-0-3-4-1-4-3-1.html' title='&lt;=&gt;'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-13884136971895760</id><published>2008-05-03T07:29:00.000-07:00</published><updated>2008-05-03T07:42:25.434-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>test</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;require  'test/unit'&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;assert_equal&lt;/span&gt;&lt;/div&gt;&lt;div&gt;if two parameter are equal, return true&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;assert_equal("dd", "ee")&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-13884136971895760?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/13884136971895760/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=13884136971895760' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/13884136971895760'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/13884136971895760'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/test.html' title='test'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5826218122871076723</id><published>2008-05-03T07:24:00.001-07:00</published><updated>2008-05-03T07:28:16.846-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>ri  command</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;read the information about ruby API&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;ri  Test::Unit&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5826218122871076723?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5826218122871076723/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5826218122871076723' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5826218122871076723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5826218122871076723'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/ri-command.html' title='ri  command'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5115370783601351512</id><published>2008-05-03T07:16:00.001-07:00</published><updated>2008-05-03T07:16:54.275-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>alias</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;define another method name&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #0000ff"&gt;&lt;span style="letter-spacing: 0.0px"&gt;alias  :puts_2  :puts&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #0000ff"&gt;&lt;span style="letter-spacing: 0.0px"&gt;puts_2  “ hello”&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;  “hello”&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5115370783601351512?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5115370783601351512/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5115370783601351512' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5115370783601351512'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5115370783601351512'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/alias.html' title='alias'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3305395936272242918</id><published>2008-05-03T07:07:00.000-07:00</published><updated>2008-05-03T07:08:06.046-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>system</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;call extern program &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #0000ff"&gt;&lt;span style="letter-spacing: 0.0px"&gt;System( “ls”)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3305395936272242918?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3305395936272242918/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3305395936272242918' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3305395936272242918'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3305395936272242918'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/system.html' title='system'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3258183040818674029</id><published>2008-05-03T06:57:00.000-07:00</published><updated>2008-05-25T02:33:40.708-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>method naming ( end with ? or ! )</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;method that returns true or false ends with ?&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex: &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;empty?&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;method that changes the state of the object ends with!&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex: &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;save!&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;built-in methods with !&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;upcase!,  chomp!,  sort!,  reverse!&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3258183040818674029?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3258183040818674029/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3258183040818674029' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3258183040818674029'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3258183040818674029'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/method-naming-end-with-or.html' title='method naming ( end with ? or ! )'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7006826849245964270</id><published>2008-05-03T06:56:00.001-07:00</published><updated>2008-05-03T06:56:56.195-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>change value to string( interpolation)</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;use  “#{  }”&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #0000ff"&gt;&lt;span style="letter-spacing: 0.0px"&gt;a= 123&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #0000ff"&gt;&lt;span style="letter-spacing: 0.0px"&gt;b= “#{a}”+ “4”&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;  b= “1234”&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7006826849245964270?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7006826849245964270/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7006826849245964270' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7006826849245964270'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7006826849245964270'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/change-value-to-string-interpolation.html' title='change value to string( interpolation)'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-2781495197017843089</id><published>2008-05-03T06:48:00.000-07:00</published><updated>2008-05-05T09:45:14.595-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>file methods</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;read  a file:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;input_file =File.new (filename, ‘r’)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;write a file:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;output_file= File.new( filename, ‘w’)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;‘w+’: &lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;read and write.  When creating the file, the old file is overwritten &lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;'a':&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;append&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;read:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;return the content of the file in the string&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;readlines:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;output_file.readlines()&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;return an array with each line of the file&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;puts:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;output_file.puts(“hello”)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;write “hello” to output_file&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;close:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;output_file.close()&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;close the file&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;show the files and directories under directory:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Dir.open("Desktop").entries&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;---&gt; [ "." , "..", "test.c", "book"]&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;directory?&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;File.directory?("test")&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;extname:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;File.extname("test.exe")&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;--&gt; ".exe"&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-2781495197017843089?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/2781495197017843089/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=2781495197017843089' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2781495197017843089'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2781495197017843089'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/file-methods.html' title='file methods'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-966588033005254766</id><published>2008-05-03T06:44:00.000-07:00</published><updated>2008-05-03T06:45:20.852-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>environment variable</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;ENV[‘HOME’] (for unix-like)&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;ENV[‘HOMEDRIVE’]+ ENV[‘HOMEPATH’] (for windows)&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;return the path of home directory&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;on my mac , output is “/Users/Pan”&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;ARGV&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;the parameter to the ruby program&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #0000ff"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ruby test.rb  123&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ARGV[0]  is 123&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(60, 21, 3); font-family: 'Hoefler Text'; font-size: 22px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-966588033005254766?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/966588033005254766/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=966588033005254766' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/966588033005254766'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/966588033005254766'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/environment-variable.html' title='environment variable'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-1639765835414750325</id><published>2008-05-03T06:34:00.000-07:00</published><updated>2008-05-03T06:35:12.100-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>comment</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;start with #&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;=begin  &amp;amp; =end&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;use in multiple-line&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-1639765835414750325?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/1639765835414750325/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=1639765835414750325' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1639765835414750325'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1639765835414750325'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/comment.html' title='comment'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4100139272844619041</id><published>2008-05-03T06:28:00.000-07:00</published><updated>2008-05-24T19:31:13.920-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>if , else, elsif, unless</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;if and else:&lt;/span&gt;&lt;br /&gt;ex:&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;if a==3&lt;br /&gt;    puts “a==3”&lt;br /&gt;else&lt;br /&gt;    puts “a!=3”&lt;br /&gt;end&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;elsif&lt;/span&gt;&lt;/div&gt;&lt;div&gt;use elsif,  not elseif&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;unless&lt;/span&gt;&lt;/div&gt;&lt;div&gt;if ! (x==1)  &lt;/div&gt;&lt;div&gt;equals&lt;/div&gt;&lt;div&gt;unless x==1&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4100139272844619041?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4100139272844619041/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4100139272844619041' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4100139272844619041'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4100139272844619041'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/if-else.html' title='if , else, elsif, unless'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8377183579330584128</id><published>2008-05-03T01:06:00.000-07:00</published><updated>2008-05-03T05:16:24.770-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>plugin install</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0); "&gt;install for ruby&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;remote install:&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;gem  install sqlite3-Ruby&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;local install:&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); font-weight: normal; "&gt;1. get gem file from  &lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-weight: bold; "&gt;http://rubyforge.org&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); font-weight: normal;"&gt;2. gem install  &lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;scruffy-0.2.2.gem &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); font-weight: normal;"&gt;  &lt;/span&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;  ( in the directory with scruffy-0.2.2.gem)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102); font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;install for rails project&lt;/span&gt;&lt;/div&gt;remote install:&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;script/plugin  install  http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated/&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;local install:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;1. 用svn抓plugin下來&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;    &lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;svn checkout http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated/&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;2. 將plugin放到rails project下的vendor/plugins/&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8377183579330584128?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8377183579330584128/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8377183579330584128' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8377183579330584128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8377183579330584128'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/plugin-install.html' title='plugin install'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4499448466633695209</id><published>2008-05-02T20:03:00.000-07:00</published><updated>2008-05-02T20:07:18.189-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software'/><title type='text'>textmate &amp; rails 2.0</title><content type='html'>install rails 2.0 bundle&lt;div&gt;1.  download rails 2.0 bundle  &lt;a href="http://github.com/drnic/ruby-on-rails-tmbundle/tree/master"&gt;rails 2.0 bundle&lt;/a&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;2.  move rails 2.0 bundle to  &lt;span class="Apple-style-span" style="color: rgb(27, 28, 32); font-family: 'Lucida Grande'; font-size: 14px; line-height: 22px; "&gt;Library/Application Support/TextMate/Bundles,&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(27, 28, 32); font-family: 'Lucida Grande'; font-size: 14px; line-height: 22px;"&gt;     rename the bundle as  Ruby on Rails.tmbundle&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(27, 28, 32); font-family: 'Lucida Grande'; font-size: 14px; line-height: 22px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(27, 28, 32); font-family: 'Lucida Grande'; font-size: 14px; line-height: 22px;"&gt;3.  reload bundle in textmate&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(27, 28, 32); font-family: 'Lucida Grande'; font-size: 14px; line-height: 22px;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(27, 28, 32); font-family: 'Lucida Grande'; font-size: 14px; line-height: 22px;"&gt;4. mv Builder.rb Builder.rb.off   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(27, 28, 32); font-family: 'Lucida Grande'; font-size: 14px; line-height: 22px;"&gt;    in  Applications/TextMate.app/Contents/SharedSupport/Support/lib&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4499448466633695209?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4499448466633695209/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4499448466633695209' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4499448466633695209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4499448466633695209'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/textmate-rails-20.html' title='textmate &amp; rails 2.0'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-1499426831318256005</id><published>2008-05-02T10:07:00.000-07:00</published><updated>2008-05-07T06:56:48.042-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software'/><title type='text'>textmate shortcut</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;select word:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); font-weight: normal; "&gt;ctrl + w&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;show bundle list&lt;/span&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;ctrl + esc&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;select bundle item:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;ctrl + command + t&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;show bundle editor:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;ctrl + option+ command + b&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;ToDo bundle:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;show ToDo list&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;ctrl + shift + t&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Define TODO: ,  FIXME: ,  CHANGED:   in the comment of the file.&lt;/div&gt;&lt;div&gt;Then show ToDo list will find there lines in the files&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0); font-weight: bold; "&gt;html  bundle:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;insert open &amp;amp; close tag with current word&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;ctrl + &lt;&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;enter head, then with this short cut,  it becomes &lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;enter this short cut, then enter abc, it becomes &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;wrap selection in open &amp;amp; close tag&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;ctrl + shift + w&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;enter hello, then enter this short cut,  then enter head, it becomes hello&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;tab completion :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;1. head:   &lt;/span&gt;&lt;/div&gt;&lt;div&gt;    head+ meta + title&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;2. style:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;3. script:&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;4. doctype:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;insert a link(with the word in the clipboard)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;ctrl + shift + L&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;webpage preview:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); font-weight: normal; "&gt;ctrl + option+ command + p&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0); font-weight: bold; "&gt;ruby  bundle:&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;run ruby program&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;command + r&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;# =&gt;  mark&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;add # =&gt; mark&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;# + tab&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;execute the line with # =&gt; mark&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;ctrl + shift + command + e&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;find doc about the word&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;ctrl + h&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-weight: bold; "&gt;tab completion :&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;1. cla :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    for class&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;2. def :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;     for method&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;3.  r ,  w,  rw&lt;/span&gt;&lt;/div&gt;&lt;div&gt;     for attr_reader(),  attr_writer(),  attr_accessor()&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;4. while &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;5.  if&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;6.  inj: &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    &lt;/span&gt; for inject&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;7. ea:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    for each&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;8. tim:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    for times&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;9. sorb:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    for sort_by&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;10. eawi:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;      each_with_index&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;rubyOnRails bundel:&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;activate rubyOnRails bundle:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;ctrl + option + shift + r + 3&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;params completion:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;ctrl + p&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;session completion:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;ctrl + j&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;call generate script:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;ctrl + | + 1&lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;tab completion:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;for model: &lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); "&gt;1. mccc &lt;/span&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;    for model create column continue&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;2.  t.&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     &lt;/span&gt;提示column type&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;3. mcol&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    create column&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-1499426831318256005?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/1499426831318256005/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=1499426831318256005' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1499426831318256005'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1499426831318256005'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/textmate-shortcut.html' title='textmate shortcut'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3283241373944661358</id><published>2008-05-02T09:38:00.000-07:00</published><updated>2008-05-02T10:07:21.999-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='software'/><title type='text'>visor : terminal access</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;1. install SIMBL&lt;/span&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;2. install visor&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span"  style=" ;font-family:arial;"&gt;provides a systemwide terminal window accessible via a hotkey&lt;/span&gt; &lt;/div&gt;&lt;div&gt;my hot key:  command + 1&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3283241373944661358?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3283241373944661358/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3283241373944661358' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3283241373944661358'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3283241373944661358'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/software-to-help-programming.html' title='visor : terminal access'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4592323227863547636</id><published>2008-05-02T01:50:00.000-07:00</published><updated>2008-05-27T09:03:31.168-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>date and time method</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;require 'date'&lt;/div&gt;&lt;div&gt;require 'time'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;Time.now  or Time.new&lt;/span&gt;&lt;div&gt;--&gt;  Fri May 02 16:50:08 +0800 2008&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Time.now.strftime('%Y-%m-%d')&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt;  "2008-05-02"&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;SECOND_IN_A_DAY&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;兩個時間相減得到的單位是秒 &lt;/b&gt;&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Date.today:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%Y, %y:  year&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%b, %B: month&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%m : month(number)&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%d, %e:  day of month&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%a, %A: dat name( such as Tue)&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%H, %I: hour&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%M: minute&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%S: second&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%c:  equals "%a %b %d %H:%M:%S %Y"&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%x:  equals "%m/%d/%y"&lt;/span&gt;&lt;/p&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4592323227863547636?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4592323227863547636/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4592323227863547636' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4592323227863547636'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4592323227863547636'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/date-method.html' title='date and time method'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6350071474984235866</id><published>2008-05-01T09:51:00.000-07:00</published><updated>2008-05-24T19:47:41.943-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>block and yield</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;yield: &lt;/span&gt;&lt;div&gt;run what block defines&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;def  test(*args, &amp;amp;block)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;        yield(*args)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;test("hello"){ |i| puts i }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt; hello&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;note:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;yield(*args)  = block.call(*args)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;when defining a method that receives blocks,&lt;/div&gt;&lt;div&gt;there are two ways&lt;/div&gt;&lt;div&gt;(1)  define method with block arguments&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def test( &amp;amp;block)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;(2)define method without block arguments&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;pass arguments to blocks&lt;/span&gt;&lt;/div&gt;&lt;div&gt;in the method definition, call yield with arguemtns&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;yield (a, b, c)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;in the block, use | | to receive arguments &lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;| a, b, c|&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;return value from call block&lt;/span&gt;&lt;/div&gt;&lt;div&gt;the return value is last expression evaluated in block&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;in the method definition&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a= yield&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6350071474984235866?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6350071474984235866/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6350071474984235866' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6350071474984235866'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6350071474984235866'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/block-and-yield.html' title='block and yield'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8018391807697384883</id><published>2008-05-01T09:26:00.001-07:00</published><updated>2008-05-04T00:39:19.850-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>here doc</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;build up a long string&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;NAME= &amp;lt;&amp;lt;END_MY_STRING&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;      hello&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;      how are you&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;END_MY_STRING&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;puts NAME&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;   hello&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;         how are you&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8018391807697384883?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8018391807697384883/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8018391807697384883' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8018391807697384883'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8018391807697384883'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/here-doc.html' title='here doc'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3623190912875615518</id><published>2008-05-01T07:31:00.001-07:00</published><updated>2008-05-18T07:22:32.104-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>required, optional, default-valued parameters</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;required parameter:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;def  test1( name)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;default value parameter&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;def  test2(name=”peter”)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;呼叫test2時，若是沒傳參數，則name=”peter”, &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;若是傳參數”andy”，則name=”andy”&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;optional parameter&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;use *&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;def test(*abc)&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;abc可接受多個參數，以array表示&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;例如呼叫test(1,2)&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;則p abc 印出 [1, 2]&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;note: optional parameter must be last parameter of the method&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3623190912875615518?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3623190912875615518/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3623190912875615518' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3623190912875615518'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3623190912875615518'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/method.html' title='required, optional, default-valued parameters'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6896900959978352407</id><published>2008-05-01T07:14:00.000-07:00</published><updated>2008-05-04T00:45:13.199-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>block, proc and &amp;</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;call method with block parameter:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;two syntaxes:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;1.  {   } &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;     this is useful for one line&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;2. do   end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;    this is useful for multiple line&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;["a", "b"].each do |i|&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    puts "#{i}"&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;the element between |  | refers to each element in the array  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;define a method with block parameter&lt;/span&gt;&lt;div&gt;use &amp;amp;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;class Array&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     def test( &amp;amp;arg)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;           find_all( &amp;amp;arg)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     end    &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-weight: bold; "&gt;pass proc parameter to a method received block&lt;/span&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-weight: normal; "&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a=lambda{ puts "abc"}&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;test(&amp;amp;a)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6896900959978352407?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6896900959978352407/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6896900959978352407' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6896900959978352407'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6896900959978352407'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/block-proc-and.html' title='block, proc and &amp;'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-2503582784824165988</id><published>2008-05-01T05:20:00.000-07:00</published><updated>2008-05-01T09:35:16.721-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>lambda  and proc</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;lambda:&lt;/span&gt;&lt;div&gt;parameter:  block&lt;/div&gt;&lt;div&gt;return: an instance of class Proc&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Proc:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;procedure&lt;/div&gt;&lt;div&gt;method:  &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;call:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;tell proc to do sth&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;test = lambda { |i| i + 1 }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;test.call(2)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt; 3&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;the method to pass parameters&lt;/div&gt;&lt;div&gt;1. test.call(2) &lt;/div&gt;&lt;div&gt;2.  test[2]&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;another method to create Proc:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Proc.new {   }&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-2503582784824165988?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/2503582784824165988/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=2503582784824165988' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2503582784824165988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2503582784824165988'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/lambda-and-proc.html' title='lambda  and proc'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6019242087903111836</id><published>2008-05-01T01:19:00.000-07:00</published><updated>2008-05-01T02:06:53.232-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><category scheme='http://www.blogger.com/atom/ns#' term='rails general'/><title type='text'>IDE</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;textmate :&lt;/span&gt; &lt;div&gt;mac, not free&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;aptana studio: &lt;/span&gt;&lt;/div&gt;&lt;div&gt; mac &amp;amp; windows, free&lt;/div&gt;&lt;div&gt; include RadRails&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;3rdRail:  &lt;/span&gt;&lt;/div&gt;&lt;div&gt;mac &amp;amp; windows, free&lt;br /&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;NetBeans:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;mac &amp;amp; windows, free&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6019242087903111836?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6019242087903111836/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6019242087903111836' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6019242087903111836'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6019242087903111836'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/05/ide.html' title='IDE'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5934560613019798238</id><published>2008-04-30T10:28:00.001-07:00</published><updated>2008-04-30T10:29:29.462-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>web api</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;open-uri&lt;/span&gt;&lt;div&gt;get date from URI&lt;/div&gt;&lt;div&gt;add   &lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;require 'open-uri'&lt;/span&gt;   in the program&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5934560613019798238?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5934560613019798238/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5934560613019798238' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5934560613019798238'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5934560613019798238'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/web-api.html' title='web api'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7335549103946884630</id><published>2008-04-30T10:18:00.000-07:00</published><updated>2008-04-30T10:26:07.773-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>YAML</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;load:&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;YAML.load(File.open("test.yaml") )&lt;/span&gt;&lt;/div&gt;&lt;div&gt;return the content in test.yaml&lt;/div&gt;&lt;div&gt;such as  "name:  peter" return  'name'=&gt;'peter'&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;dump:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;write to YAML file&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;File.open("test.yaml", w) {  |output|  YAML.dump(names, output) }&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7335549103946884630?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7335549103946884630/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7335549103946884630' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7335549103946884630'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7335549103946884630'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/yaml.html' title='YAML'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7348414004240805033</id><published>2008-04-30T10:00:00.001-07:00</published><updated>2008-05-24T19:57:44.323-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>error handling:  rescue &amp; raise</title><content type='html'>&lt;div&gt;handle exception:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;ex:&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;      puts  1/0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;rescue&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     puts "error"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;---&gt;  "error"&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;rescue can for specific exception:&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;begin&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     puts 1/0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rescue  ZeroDivisionError&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;     puts "error"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;rescue for method&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    puts "test"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rescue&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;    puts "rescue"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;       &lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;raise&lt;/span&gt;&lt;/div&gt;&lt;div&gt;raise exception&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;def test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;   raise  ArgumentError,  "argument error"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;the second argument is the message printed&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;get the exception&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;rescue ArgumentError =&gt;  e&lt;/span&gt;&lt;/div&gt;&lt;div&gt;e is the exception &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;define exception&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class  TestException  &lt;&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7348414004240805033?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7348414004240805033/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7348414004240805033' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7348414004240805033'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7348414004240805033'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/begin-rescue-end.html' title='error handling:  rescue &amp; raise'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-5240054471847331467</id><published>2008-04-30T08:11:00.000-07:00</published><updated>2008-04-30T08:12:15.225-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>range</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;(‘A’..’Z’)&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;0..9&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-5240054471847331467?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/5240054471847331467/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=5240054471847331467' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5240054471847331467'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/5240054471847331467'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/range.html' title='range'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3364519697789467655</id><published>2008-04-30T07:53:00.000-07:00</published><updated>2008-05-05T08:24:35.989-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>define class</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;class Rabbit&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;    def  initialize( name)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;        @name = name&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;    end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;    def run &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;        puts “run”&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;    end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;initialize:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;this method is called when the object is created&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;this is a private method. Hence, when using new to create object, the new method will call initialize &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;instance variable:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;the variable that starts with @ is instance variable&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;naming convention:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;class name:  CuteRabbit&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;file name : cute_rabbit.rb&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;private:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;the method is private&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;define methods after private&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;private  &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;def  test&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;protected:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;the method is protected&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;modify existing class&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:  the Array is built-in class.&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;class Array&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    def test&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    end&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;now the Array has new method test&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;class variable:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;the variable that starts with @@ is class variable&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); font-weight: bold; "&gt;class method:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 0); "&gt;ex:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;def self.test&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;inheritance:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class Circle  &amp;lt; Shape&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;if class Square is defined inside class Shape, you must access Square with&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;Shape::Square outside class Shape&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;class Test  &amp;lt; Shape::Square&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;end&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;constant in the class&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;if TEST is the constant of class Rabbit,&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;we can access Test using Rabbit::Test&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; min-height: 22px; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3364519697789467655?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3364519697789467655/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3364519697789467655' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3364519697789467655'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3364519697789467655'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/define-class.html' title='define class'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3206858681343717607</id><published>2008-04-30T07:51:00.001-07:00</published><updated>2008-05-20T09:26:51.714-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>constant</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;use capital letter&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;Apple,  Rabbit&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;access constant define in class&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;Name is defined in the class Rabbit&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;Rabbit::Name&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3206858681343717607?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3206858681343717607/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3206858681343717607' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3206858681343717607'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3206858681343717607'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/constant.html' title='constant'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6298205418013389229</id><published>2008-04-30T07:49:00.001-07:00</published><updated>2008-06-10T06:56:07.675-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>hash</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;hash is declared inside { }&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;animal= { &lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    :one=&gt; “dog”,&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    :two=&gt;”rabbit”&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;說明:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;animal[:one] = “dog”&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;animal[:two]=”rabbit”&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;animal= {&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    :one=&gt;[‘v’, ‘version’ ]&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;CONSTANT is often defined as hash&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;OPTIONS={&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    :command=&gt;[‘r’, ‘run’]&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;keys:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;return the keys of hash in the array&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;{ :a=&gt;”name”, :b=&gt;”age”}.keys&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;--&gt;  [ :a,  :b ]&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;values:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;return the values of hash in the array&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;{ :name=&gt;"peter"}.values&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;---&gt;  ["peter"]&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;values_at&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;get multiple element&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;{ :a=&gt;"a", :b=&gt;"b", :c=&gt;"c"}.values_at(:a,:b)&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;---&gt; ["a", "b"]&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;has_key? :&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;{:a=&gt;"a"}.has_key?(:a)&lt;/span&gt;&lt;/p&gt;&lt;div&gt;---&gt;  true&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;sort_by:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;由小排到大&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a={ :c=&gt;"C", :b=&gt;"B" }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a.keys.sort_by{ |i| a[i] }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt; [:b, :c]&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;sort_by{ |a, b| }&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;sort according to a first, according to b in case of a tie&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;merge:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;{ :a=&gt;"a", :b=&gt;"b"}.merge( {:a=&gt;"c", :d=&gt;"d" } )&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt;  { :a=&gt;"c", :d=&gt;"d",  :b=&gt;"b" }&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;each_key:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;c= { :a=&gt;"aa", :b=&gt;"bb"}&lt;/span&gt;&lt;/p&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;{ :a=&gt;"aa", :b=&gt;"bb"}.each_key { |i| puts c[i] }&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt;  aa&lt;/div&gt;&lt;div&gt;      bb&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;each_pair:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;{ "name"=&gt;"peter"}.each_pair do |i,j|&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     puts   i+ " "+ j&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153); font-weight: normal;"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;---&gt; name peter&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;sort:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;return nested array&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;default(without pass block parameter) :&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ascending order  &amp;amp; compare hash's value&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;{ "b"=&gt;1,  "a"=&gt;2}.sort&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;--&gt; [ ["b", 1],  ["a", 2] ]&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Hash.new(0)&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;set default value of hash for nonexistent keys, the key is still nonexistent&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a =Hash.new(0)&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a[2]&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;---&gt;  0&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;set default value of hash for nonexistent keys, the key is added&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;ex:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a=Hash.new { |hash, key| hash[key]=0 }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: normal;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6298205418013389229?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6298205418013389229/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6298205418013389229' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6298205418013389229'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6298205418013389229'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/hash.html' title='hash'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-2218424062858619098</id><published>2008-04-30T07:48:00.000-07:00</published><updated>2008-04-30T07:49:04.089-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>RDoc</title><content type='html'>&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;=begin rdoc&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;    &lt;b&gt;RDoc comments&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;=end&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503; min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color: #3c1503"&gt;&lt;span style="letter-spacing: 0.0px"&gt;allow HTML-like tagging&lt;/span&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-2218424062858619098?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/2218424062858619098/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=2218424062858619098' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2218424062858619098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2218424062858619098'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/rdoc.html' title='RDoc'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7444519538277174362</id><published>2008-04-30T07:47:00.000-07:00</published><updated>2008-05-05T03:59:46.014-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>each, each_with_index, map</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;each:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;accept block parameter that describe what to do with each element of array or hash&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex: &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;[“A”, “B”].each do |i|&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;       puts “#{i}”&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;  A&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;        B&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;each_index:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;/p&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;["A", "B"].each_index do |i|&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    puts "#{i}"&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;each_with_index:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;['a','b','c'].each_with_index do |content, index|&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;puts "#{content}#{index}"&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;end&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt; a0&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;       b1&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;       c2&lt;/span&gt;&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;&lt;/b&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;map:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;v.s each: different in return &lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;it return the new value, &lt;span class="Apple-style-span" style="color: rgb(0, 102, 0);"&gt;each&lt;/span&gt; return original value&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;[1,2,3].map{ |i| i*2 }&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;[2,4,6]&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;map! will change content of caller&lt;/span&gt;&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7444519538277174362?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7444519538277174362/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7444519538277174362' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7444519538277174362'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7444519538277174362'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/each-eachwithindex-map.html' title='each, each_with_index, map'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-1132469897894007863</id><published>2008-04-30T07:46:00.000-07:00</published><updated>2008-06-11T08:52:32.455-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>array</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;enclosed with [ ]&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt; &lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;can contain elements with different classes&lt;br /&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;  &lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;add element to array:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;use &lt;&lt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a=[]&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a &lt;&lt;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;array adding&lt;/span&gt;&lt;br /&gt;ex:&lt;br /&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt; [“test1”] + [“test2”] &lt;/span&gt;&lt;br /&gt;--&gt;  [ “test1”,  “test2” ]&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;use concat:&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;[1,2].concat([3,4])&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;--&gt; [1,2,3,4]&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;concat modifies original array&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style=""&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;&lt;:&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;add element to array&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a=[1,2]&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a&lt;&lt;3&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;---&gt; [1,2,3]&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;new:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Array.new(3, "a")&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;create a three element array ,with each initialized to "a"&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a=0&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Array.new(3) { a=a+1 }&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;create a three element array , [1,2,3]&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;get more than one elements&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a=[1,2,3,4,5]&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a[3,2] &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;---&gt;  [4,5]&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;sort_by&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;accept block argument&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;sort_by{ rand }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;sort randomly &lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;join:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;[“a”, “b”, “c”].join(‘2’)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;--&gt;  “a2b2c”&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;push:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;add an element to the end of the array&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;pop:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;remove last element&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;include:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;[1, 2, 3].include?(1)&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;  true&lt;/span&gt;&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;uniq:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;["ab", "c","ab"].uniq&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;["ab", "c"]&lt;/span&gt;&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;multiplication:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;[1,2]*2&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;--&gt; [1,2, 1,2]&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;detect:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;find the first element that match condition in the array&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;[1 , 2, 3].detect { | i |  i&gt;2 }&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt; 3&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;find:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;find first element that matches  &lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;find_all:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;find all elements that match condition in the array&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;[1,2,3].find_all{ |i| i&gt;1 }&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt;  [2, 3]&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;array intersection:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;use &amp;amp;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;[1,2,3] &amp;amp; [2,3]&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt; [2,3]&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;%w[a b]&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt; ["a",  "b"]&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;sort:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;c=[ [1, 2], [3, 1] ]&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;c.sort{ |a, b| a[0]&lt;=&gt;b[0] }&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt;  [ [1,2], [3, 1] ]&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;c.sort{ |a, b| b[0]&lt;=&gt;a[0] } &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt;   [[3, 1], [1, 2]]&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;c.sort{ |a, b| a[1]&lt;=&gt;b[1] } &lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt;   [[3, 1], [1, 2]]&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;a[0] &lt;=&gt; b[0] compare first element of nested array in ascending order&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;a[1] &lt;=&gt; b[1] compare second element of nested array in ascending order&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;b[0] &lt;=&gt; b[1] compare first element of nested array in descending order&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;unshift:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;add an element to the beginning of the array&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;shift:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;remove the first element &lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;zip:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;[1,2].zip([3,4])&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt; [ [1,3],  [2,4] ]&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;flatten:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;[1,2, [3,4] ].flatten&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;--&gt; [1,2,3,4]&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;reject:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;[1,2,3].reject { |item|  item&gt;2 }&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;---&gt; [1,2]&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;replace, reverse:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;each, each_with_index&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;include?,  empty?, any?, all?&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;[1,2,3].any?{ | k|  k&gt;2 }&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;---&gt; true&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;index:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;return the first element equals to parameter&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;["a", "b", "c"].index( "b")&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;---&gt; 1&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;index   with  integer &lt;0&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;count from right&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a= [1, 2, 3]&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a[-1]  &lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;---&gt;  3&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;compact:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;remove nil element from the array&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-1132469897894007863?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/1132469897894007863/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=1132469897894007863' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1132469897894007863'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/1132469897894007863'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/array.html' title='array'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-2758540269874170250</id><published>2008-04-30T07:40:00.000-07:00</published><updated>2008-05-05T09:24:12.272-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>regular expression</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;use /  /  to include regular expression&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;/a/&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;test regular expression match:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;use =~&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex: &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;“hello”=~ /el?/&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;  1&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;? :&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;zero or more occurrence &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;+:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;one or more occurrence&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;\W:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;any whitespace&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;\{X}:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a{3}&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;--&gt;  three  a&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;\d:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;any digit&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;\:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;treat the special character after it as normal character &lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;^ :&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;anchor for the beginning of a line&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;$:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;anchor for the end of a line&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;*:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;match 0 or more occurrences of preceding character &lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Regexp.new:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;ex:&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;Regexp.new("test")&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;---&gt; /test/&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-2758540269874170250?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/2758540269874170250/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=2758540269874170250' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2758540269874170250'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/2758540269874170250'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/regular-expression.html' title='regular expression'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-8688772306285731757</id><published>2008-04-30T07:37:00.000-07:00</published><updated>2008-06-10T06:05:11.712-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>string method</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;crate string array&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;%w[AB CD]&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt; [“AB”, “CD”]&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;gsub &amp;amp; gsub!:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;global substitution &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"hello".gsub("e","a")&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;  "hallo"&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;gsub! will change original string&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;gsub &amp;amp; sub:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;gsub change every match, sub only change first match&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;ex:&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"helleo".gsub("e","a")&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;--&gt; "hallao"&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"helleo".sub("e","a")&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;--&gt; "halleo"&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;sprintf:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:  &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;sprintf(“%2d”, 3)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;--&gt; “  3”&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;inject:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;[1, 2,3].inject(10) {  | sum, number|  sum=sum+number }&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;--&gt; 16&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;inject初始sum為10，&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;然後10+1=11&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;11+2=13&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;13+3=16&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;chomp:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;remove the newline character&lt;/span&gt;&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;chop:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;remove last character &lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;grep:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;["test", "b", "testa", "test"].grep("test")&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;---&gt;["test", "test"]&lt;/span&gt;&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;split:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span style="letter-spacing: 0.0px"&gt;ex:  &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;“hello”.split(‘e’)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt; ---&gt;["h", "llo"]&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;ex:   &lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a, b= "hello".split('e')&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;--&gt; a= "h", b="llo"&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;chr:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a= "abcde"&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;a[0].chr&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;--&gt;  "a"&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;strip:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;return a copy with leading and tailing whitespace removed&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;lstrip &amp;amp; rstrip&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;removing left or right whitespace &lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%q :&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;create string, single-quoted&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;%q (abc)&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;---&gt; "abc"&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%Q: &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;create string, double-quoted &lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;\ :&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;use \ to escape:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;puts "abc\"de"&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;---&gt;  abc"de&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;&lt;:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;add string(modify original string)&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a="test"&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a&lt;&lt; "abc:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;puts a&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;--&gt;  testabc&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;replace:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a="test"&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a.replace("abc")&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;puts a&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;---&gt; abc&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;reverse,  downcase, upcase, capitalize, swapcase &lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;substring:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"abcde"[2,2]&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;---&gt;  "cd"&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a="abcde"&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a[2,2]="gg"&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;a&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;---&gt; "abgge"&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;succ:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"abc".succ&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;--&gt; "abb"&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;br /&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;%:&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;format string&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;ex:&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;"%.2f"%3.333&lt;/span&gt;&lt;/p&gt;&lt;p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; font: normal normal normal 18px/normal 'Hoefler Text'; "&gt;---&gt;"3.33"&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-8688772306285731757?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/8688772306285731757/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=8688772306285731757' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8688772306285731757'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/8688772306285731757'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/string-method.html' title='string method'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-7728175980318554557</id><published>2008-04-30T07:33:00.000-07:00</published><updated>2008-05-20T22:01:58.790-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>module</title><content type='html'> module is like class,  but it can not be instantiated&lt;div&gt; support methods for other class&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;use &lt;span class="Apple-style-span" style="color: rgb(0, 51, 0);"&gt;include&lt;/span&gt; to include module&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;a class can only have inherit from one class, but it can mix in more than one mouels&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;module Animal&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    def   test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;    ned&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end &lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;class Rabbit&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;      include Animal&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;      def  run&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;           test&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;     end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;end&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;if a class include two modules,  M1 &amp;amp; M2( M2 is included last),&lt;/div&gt;&lt;div&gt;M1 &amp;amp; M2 both have method test&lt;/div&gt;&lt;div&gt;When the object of the class calls method test,&lt;/div&gt;&lt;div&gt;it will call M2's test&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-7728175980318554557?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/7728175980318554557/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=7728175980318554557' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7728175980318554557'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/7728175980318554557'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/module.html' title='module'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-6562686668537394144</id><published>2008-04-30T07:30:00.000-07:00</published><updated>2008-04-30T07:32:45.834-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>require</title><content type='html'>use external file&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;require 'test'&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;t= Test.new&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Test class is defined in another file( test.rb)&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-6562686668537394144?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/6562686668537394144/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=6562686668537394144' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6562686668537394144'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/6562686668537394144'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/require.html' title='require'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-4859781901083810334</id><published>2008-04-30T06:37:00.000-07:00</published><updated>2008-05-27T08:55:52.398-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>math methods</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;abs:&lt;/span&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;-3.abs&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt; 3&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;zero?&lt;/span&gt;&lt;/div&gt;&lt;div&gt;tell if the number is zero&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;3.zero?&lt;/span&gt;&lt;/div&gt;&lt;div&gt;--&gt; false&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;rand:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 153);"&gt;rand(100)&lt;/span&gt;&lt;/div&gt;&lt;div&gt;return an random integer from 0 to 99&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;round:&lt;/span&gt;&lt;/div&gt;&lt;div&gt;ex:&lt;/div&gt;&lt;div&gt;3.1.round &lt;/div&gt;&lt;div&gt;--&gt; 3&lt;/div&gt;&lt;div&gt;3.5.round &lt;/div&gt;&lt;div&gt;---&gt;4&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-4859781901083810334?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/4859781901083810334/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=4859781901083810334' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4859781901083810334'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/4859781901083810334'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/math-methods.html' title='math methods'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6084390055539385063.post-3161233199689665600</id><published>2008-04-30T04:29:00.001-07:00</published><updated>2008-05-12T11:17:14.061-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='ruby'/><title type='text'>useful utilities (irb, ruby)</title><content type='html'>&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;irb:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;    a shell to run ruby &lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#0000ff;"&gt;&lt;span style="letter-spacing: 0.0px ;color:#3c1503;"&gt;    &lt;/span&gt;&lt;span style="letter-spacing: 0.0px"&gt;irb  -r  test.rb&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;    include the content of test.rb,  r is require&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;/span&gt;&lt;br /&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;ruby:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;&lt;b&gt;-w:&lt;/b&gt;&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text; color:#3c1503;"&gt;&lt;span style="letter-spacing: 0.0px"&gt;turn warnings on for your script&lt;/span&gt;&lt;/p&gt; &lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;-e:&lt;/span&gt;&lt;/p&gt;&lt;p  style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;execute the code in '  '&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;ex:&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="color: rgb(0, 0, 102);"&gt;ruby -e  'puts "hello"  '&lt;/span&gt;&lt;/p&gt;&lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;---&gt;  hello&lt;/p&gt; &lt;p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0pxcolor:#3c1503;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;-r:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;require some files&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;-rdebug:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;debug program,&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;step command:  run next instruction &lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;-r profile:&lt;/span&gt;&lt;/p&gt;&lt;p color="#3c1503" style="margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Hoefler Text;  min-height: 22.0px"&gt;test performance&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6084390055539385063-3161233199689665600?l=deeplyloverubyonrails.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://deeplyloverubyonrails.blogspot.com/feeds/3161233199689665600/comments/default' title='張貼意見'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=6084390055539385063&amp;postID=3161233199689665600' title='0 個意見'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3161233199689665600'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6084390055539385063/posts/default/3161233199689665600'/><link rel='alternate' type='text/html' href='http://deeplyloverubyonrails.blogspot.com/2008/04/useful-utilities-irb-ruby.html' title='useful utilities (irb, ruby)'/><author><name>deeplove</name><uri>http://www.blogger.com/profile/10859592301681118171</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
