あ伊藤です.本質と関係ありませんが...


In article <199802030559.OAA11780 / blade.nagaokaut.ac.jp>,
	Shin-ichiro HARA  <ruby-list / netlab.co.jp> writes:

> |2. 複数の手続きを指定する事が出来ない。
> 
> 昔、イテレータの効用について「制御構造を定義できる」というのが
> あったけど、if () then {} else {} end がつくれへんやんけ、と思っ
> たのは私だけではないみたいですね。:-)

こんなのはいかが? :-)

class IF_exec
  def initialize(z)
    @else = z
  end
  def ELSE
    if @else then
      yield
    end
  end
end

def IF (cond)
  if cond then
    yield
    return IF_exec.new(false)
  else
    return IF_exec.new(true)
  end
end
    
while gets
  x = $_.to_i
  IF (x%2 == 0) {
    print "even number\n"
  } .ELSE {
    print "odd number\n"
  }
end


こういう中間的なデータ構造を作る方法は,C++ ではよく使う手なんですが
(マニピュレータとか),ruby でやると,いかにも汚い...
--_
ITO  Akinori at YAMAGATA UNIVERSITY
伊藤 彰則       山形     大学