<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>数奇な因子 &#187; ruby</title>
	<atom:link href="http://www.numericalfactor.org/wp/tag/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://www.numericalfactor.org/wp</link>
	<description>Numerical Factor</description>
	<lastBuildDate>Sun, 02 May 2010 09:50:48 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>ja</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>初めてのRuby（続き）</title>
		<link>http://www.numericalfactor.org/wp/archives/295</link>
		<comments>http://www.numericalfactor.org/wp/archives/295#comments</comments>
		<pubDate>Sun, 19 Oct 2008 15:16:16 +0000</pubDate>
		<dc:creator>line</dc:creator>
				<category><![CDATA[book]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.numericalfactor.org/wp/?p=295</guid>
		<description><![CDATA[「初めてのRuby」の残りを読んで，新たに知ったことなど．

ヒアドキュメント．Stringの%メソッドを合わせることで，
長い文字列もすっきり．
今まで何と無駄で読みにくいコードを書いていたのかと．

変数が保持するも [...]]]></description>
			<content:encoded><![CDATA[<p>「初めてのRuby」の残りを読んで，新たに知ったことなど．</p>

<p>ヒアドキュメント．<code>String</code>の%メソッドを合わせることで，
長い文字列もすっきり．
今まで何と無駄で読みにくいコードを書いていたのかと．</p>

<p>変数が保持するものは，オブジェクトへの参照．ラベル付け．
どこからも参照されなくなるとGCのときに回収される?</p>

<p><code>nil/false</code>は偽であること，
変数は大体初期値が<code>nil</code>であること，
論理演算子が真偽値ではなくオペランドを返すことを利用して，
次のような初期化イディオムが使える．</p>

<pre><code>  @instance_var ||= some_value
</code></pre>

<p><code>if/for/while/case</code>は値を返す制御文なので制御式と呼ばれる．
ていうか値を返すのか．</p>

<pre><code>some_var = if some_cond then
  value
else
  another_value
end
</code></pre>

<p><code>case</code>制御式のために<code>case</code>比較演算子<code>===</code>がある．</p>

<p><code>catch/throw</code>でネストしたループを脱出．
自分はたまに再帰で構文解析とかやるとC++の例外でほぼ同じような事を…．</p>

<p>コードブロックをオブジェクトとして扱う．
確かにイテレータメソッドは幾度も使って慣れてきたけど，
<code>Proc</code>でコード片をオブジェクトにして渡し，
あとで使うなどということを意識してやったことはなかった．</p>

<p><code>attr_accessor</code>メソッドで属性定義が簡単にできる．
以下のように書くと，<code>Student</code>クラスに<code>name/student_id</code>の
getterとsetterが自動で定義される．</p>

<pre><code>class Student
  attr_accessor :name, :student_id

  def to_s
    "#{@name}, \##{@student_id}"
  end
end

student = Student.new
student.name = "line"
student.student_id = "1234cs567"
puts student    #=&gt; line, #1234cs567
</code></pre>

<p>特異メソッド，特異クラス，メタクラスの関係がまだ把握できていない．
ここでいう「特異」は&#8221;singleton&#8221;と訳すと知った． singularかと思ってました．</p>
]]></content:encoded>
			<wfw:commentRss>http://www.numericalfactor.org/wp/archives/295/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>初めてのRuby</title>
		<link>http://www.numericalfactor.org/wp/archives/278</link>
		<comments>http://www.numericalfactor.org/wp/archives/278#comments</comments>
		<pubDate>Wed, 08 Oct 2008 15:39:11 +0000</pubDate>
		<dc:creator>line</dc:creator>
				<category><![CDATA[book]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.numericalfactor.org/wp/?p=278</guid>
		<description><![CDATA[<p>すみませんがサーバでエラーが起こりました。このページを再読込してください</p>論文書いてる間は我慢してたので，早速買ってみた．

4873113679,caption

今まで書いた自分のコードが如何に冗長かということが分かる．
Rubyを使うならRubyらしく考える…というのが必要でした．

配 [...]]]></description>
			<content:encoded><![CDATA[<p>すみませんがサーバでエラーが起こりました。このページを再読込してください</p><p>論文書いてる間は我慢してたので，早速買ってみた．</p>

<p><amazon>4873113679,caption</amazon></p>

<p>今まで書いた自分のコードが如何に冗長かということが分かる．
Rubyを使うならRubyらしく考える…というのが必要でした．</p>

<p>配列はオブジェクトへの参照を並べたコンテナ…という言葉から色々と分かった気がする．
参照を持ってるだけなら<a href="http://www.ruby-lang.org/ja/man/html/trap_Array.html">そういう動作</a>になるわけだよ．</p>

<p>イテレータと言うと，C++に慣れた自分は</p>

<pre><code>for (vector&lt;int&gt;::iterator ite = array.begin();
     ite != array.end(); ++it) {
  cout &lt;&lt; *ite &lt;&lt; endl;
}
</code></pre>

<p>でいうところの <var>ite</var> を想像するのだけど，
Rubyではブロック引数をとる<strong>メソッド</strong>がイテレータ．
何が違うのかと思い<a href="http://ja.wikipedia.org/wiki/%E3%82%A4%E3%83%86%E3%83%AC%E3%83%BC%E3%82%BF">Wikipediaを見た</a>ら，
<q>イテレータには内部イテレータと外部イテレータの区分がある</q>とのこと．なるほど．</p>

<p>Stringには%メソッドがあるのでsprintfは要らないようだ．</p>

<p>シンボルのことをinternされた文字列のようなものと言っていたけど，
まずinternが分からない自分涙目．</p>

<p>途中まで読んで，気になったのはこんなところか．知らないことがたくさんあるなぁ．</p>
]]></content:encoded>
			<wfw:commentRss>http://www.numericalfactor.org/wp/archives/278/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Frameworks for Ruby</title>
		<link>http://www.numericalfactor.org/wp/archives/261</link>
		<comments>http://www.numericalfactor.org/wp/archives/261#comments</comments>
		<pubDate>Sun, 25 May 2008 14:50:14 +0000</pubDate>
		<dc:creator>line</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.numericalfactor.org/wp/?p=261</guid>
		<description><![CDATA[某所で作っている自作cgiがいい加減gdgdなのです．


先のことを少しは考えて書いたけど，やっぱり混沌としてしまってる
自分が書くより既製品を使う方が絶対良い部分がある．認証とかセッションとか．


Rubyには慣れ [...]]]></description>
			<content:encoded><![CDATA[<p>某所で作っている自作cgiがいい加減gdgdなのです．</p>

<ul>
<li>先のことを少しは考えて書いたけど，やっぱり混沌としてしまってる</li>
<li>自分が書くより既製品を使う方が絶対良い部分がある．認証とかセッションとか．</li>
</ul>

<p>Rubyには慣れてきた(Ruby的にモノを書いてるかは疑問だけど)ので，ここはフレームワークに乗っかろうと．
探してみたところこんなのがある．</p>

<ul>
<li><a href="http://merbivore.com/">Merb</a></li>
<li><a href="http://ramaze.net/">Ramaze</a></li>
<li><a href="http://sinatrarb.com/">Sinatra</a></li>
<li><a href="http://www.nitroproject.org/">Nitro</a></li>
<li><a href="http://camping.rubyforge.org/">Camping</a></li>
</ul>

<p>まずはMerbを使ってみようかと思います．MVCについても勉強しよう．</p>
]]></content:encoded>
			<wfw:commentRss>http://www.numericalfactor.org/wp/archives/261/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
