2008-08-17から1日間の記事一覧
# -*- coding: utf-8 -*- require "rubygems" require "expectations" #6章 変数と式 Expectations do expect [true, true] do a = "aaa" b = a [a == b, a.equal?(b)] end expect [true, false] do a = "aaa" b = "aaa" [a == b, a.equal?(b)] end #多値 ex…
# -*- coding: utf-8 -*- require "rubygems" require "expectations" #7章 メソッド Expectations do #多値 expect 2 do def foo; return 1, 2, 3; end a, b, c = foo b end expect [1, 2, 3] do def foo; return 1, 2, 3; end foo end #クロージャ expect …
# -*- coding: utf-8 -*- require "rubygems" require "expectations" #8章 オブジェクトとクラス Expectations do #加算メソッドの上書き expect 3 do class Fixnum alias original_add + def +(rhs); original_add(rhs).succ; end end 1 + 1 end #上書きの…