2008-01-01から1年間の記事一覧

RCV 0.0.5

リリースしました。変更点 ・Ubuntu8.04にアップデートしたことでPixbufLoaderバグが修正された。 (Ubuntu7.10では動きません) ・上記によりTempfileを止め、メモリ内データを使用するようにしました。 ・ブックマーク機能を若干強化しました。 ・色々バグ修…

RCV

RCVというシンプルなViewerを作ったのでrubyforgeに登録しました! http://rubyforge.org/projects/rcv/ インストール gem install rcv 実行 $ rcv or $ rcv zipfilename 特徴 ・Ruby + Ruby/Gnome2環境で動作。 ・RubyZipを使いZipファイルを読み込み、画像…

Interpreter 2

デザインパターンでもインタプリタでもないのですが、前回の内容を DSLっぽくしてみました。 class Command def self.eval &block c = new c.instance_eval &block end def go puts "Go!" end def left puts "Left!" end def right puts "Right!" end end Co…

Interpreter

デザインパターン入門を読んだ後、思いだしながら 実装してみました。何か違うな。 class Itpr def self.eval str p = Program.new(Lexer.new(str), CommandExecuter.new) p.parse end end class Parser def initialize lexer, exec @lexer = lexer @execute…

WEBrick+Rack

WEBrickとRackのリクエスト処理周りを読んだ。 この様に、サーバーに依存するHandler部分 (WEBrickならservice()、Mongrelならprocess()) を吸収し、ユーザーが定義したcall()を動作させる。 require "rubygems" require "rack" class Hello def call env …

Ramaze+Rack

Ramazeを読んでいたらRackで躓いた。 そしてRackを読む。Rack楽しいっ。パズルみたいです。 Christian Neukirchen is Code artist の異名は伊達じゃないですね。http://d.hatena.ne.jp/authorNari/20080228/1204165723

興味

興味のあるキーワードを並べておきます。Thin Ramaze

仕事

最近というか、以前から仕事でC#+ASP+AJAX+Oracleしかやってない。Rubyの仕事がしたいです。

Singleton

require "singleton" module Singleton1 class Card include Singleton def use print "hello\n" end end end s1 = Singleton1::Card.instance s2 = Singleton1::Card.instance p s1 p s2 s1.use => #<Singleton1::Card:0xb7c74540> #<Singleton1::Card:0xb7c74540> hello 洗練された標準ライブラリを使いましょう。</singleton1::card:0xb7c74540></singleton1::card:0xb7c74540>

はてなブックマーク

今さらですけど、 「このエントリーを含むはてなブックマーク」ボタンを 追加しました。 Rankomic

自作Ruby on Railsアプリの

ブラウザを変えた訳でもないのに Rankomic のデザインがずれていた。なんだろこれ。

FactoryMethod その4

今回は動的にFactoryを生成しています。 るびまの添削記事からパクりました。 module FactoryMethod class IDCard def initialize(str) @owner = str end def use "#{@owner}のカードを使います" end end class Factory def create(str) create_product(str)…

FactoryMethod その3

IDCardとIDCardFactoryは強い依存関係にある。 しかも型が無いため抽象クラスのようなものは必要ない。 それらを考慮するとこうしてもいいかも。 module FactoryMethod module Factory def create(*arg) product = new(*arg) puts product.owner product end…

言語の宗教戦争

なにやら最近盛り上がってますね。 結局のところ好き嫌いあるのが当たり前なんだし、 争うだけ無駄ですよね。でも、それぞれの意見を 聞いてみるのは楽しいと思う。 ただ、PHPしかできない人がPHPをバカにされて、 反論するのはどうかと思う。その他の技術も…

Factory Method その2

module FactoryMethod class IDCard def initialize(str) @owner = str end def use "#{@owner}のカード" end end module Factory def create(*arg) product(*arg) end end class IDCardFactory include Factory def product(str) IDCard.new(str) end end e…

Factory Method その1

単純移植 module FactoryMethod class IDCard def initialize(str) @owner = str end def use "#{@owner}のカード" end end class Factory def create(*arg) create_product(*arg) end end class IDCardFactory < Factory def create_product(str) IDCard.ne…

Template Method その5

Template Method その3のモジュールを使えば、 Enumerableモジュールと同じように、こんな事もできますね。 obj = Object.new def obj.open puts "open!" end def obj.close puts "close!" end def obj.temp [:open, :close] end obj.extend(TemplateMethod:…

Template Method その4

module TemplateMethod2 class Child def open print "<" end def disp(&block) open block.call close end def close puts ">" end end end TemplateMethod2::Child.new.disp { print "H" * 5 } 初めと意味が変わってしまいましたが、 これもTemplate Metho…

Template Method その3

module TemplateMethod module Display def disp temp.each { |sym| __send__(sym) } end end class Parent include Display def temp a = [] a << :open a << [:_print] * 5 a << :close a.flatten end end class Child < Parent def initialize(str) @str …

Template Method その2

module TemplateMethod class Display def self.disp(procs) procs[:open].call procs[:_print].call procs[:close].call end end end def char_procs(str) { :open => proc { print "<" }, :_print => proc { print str * 5 }, :close => proc { puts ">" }…

Template Method その1

1つめのサンプルを、単純に移植。 module TemplateMethod class AbstractDisplay def disp open 5.times { _print } close end end class CharDisplay < AbstractDisplay def initialize(str) @str = str end def open print "<" end def _print print @str …

Adapter その2

標準ライブラリを使ってみました。 require "forwardable" class PrintBanner extend Forwardable def initialize(str) @banner = Banner.new(str) end def_delegator :@banner, :show_with_paren, :print_weak def_delegator :@banner, :show_with_aster, :…

Adapter その1

所謂ラッパーですね。まずは単純に移植。継承の場合 module Adapter class Banner def initialize(str) @str = str end def show_with_paren puts "(#{@str})" end def show_with_aster puts "*#{@str}*" end end class PrintBanner < Banner def print_weak…

Iterator その2

Rubyっぽく、まず思いついたのはこんな感じです。 module Iterator2 class Book def initialize(name) @name = name end attr_reader :name end class BookShelf def initialize @books = [] end def append(book) @books << book end def each(&block) @boo…

Iterator その1

まずはIterator。サンプルプログラムを単純に移植してみます。 module Iterator class Book def initialize(name) @name = name end attr_reader :name end class BookShelf def initialize @books = [] @length = 0 end def [](i) @books[i] end def append…

ことはじめ

単純に移植するだけなら簡単だが、いかにRubyらしく、そもそも、 Rubyならもっと素敵に実装できるのかも?をテーマに、 Rubyなりのデザインパターン実装を考えてみようと思います。結城先生の「Java言語で学ぶデザインパターン入門」の サンプルプログラムを…

Rubyソースコード完全解説

を読んでいます。gc.c (obj->as.basic.flags & FL_MARK) こんなソースを見かけるが、どんな意味があるんだろう? flagsのままじゃダメなのかな? FL_MARK(0x3f)より上位ビットをどうにかするため? (0x40)で割った時の余り? どんな状況なんだろ?プログラム…