2008-01-01から1年間の記事一覧
リリースしました。変更点 ・Ubuntu8.04にアップデートしたことでPixbufLoaderバグが修正された。 (Ubuntu7.10では動きません) ・上記によりTempfileを止め、メモリ内データを使用するようにしました。 ・ブックマーク機能を若干強化しました。 ・色々バグ修…
RCVというシンプルなViewerを作ったのでrubyforgeに登録しました! http://rubyforge.org/projects/rcv/ インストール gem install rcv 実行 $ rcv or $ rcv zipfilename 特徴 ・Ruby + Ruby/Gnome2環境で動作。 ・RubyZipを使いZipファイルを読み込み、画像…
デザインパターンでもインタプリタでもないのですが、前回の内容を 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…
デザインパターン入門を読んだ後、思いだしながら 実装してみました。何か違うな。 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のリクエスト処理周りを読んだ。 この様に、サーバーに依存するHandler部分 (WEBrickならservice()、Mongrelならprocess()) を吸収し、ユーザーが定義したcall()を動作させる。 require "rubygems" require "rack" class Hello def call env …
Ramazeを読んでいたらRackで躓いた。 そしてRackを読む。Rack楽しいっ。パズルみたいです。 Christian Neukirchen is Code artist の異名は伊達じゃないですね。http://d.hatena.ne.jp/authorNari/20080228/1204165723
興味のあるキーワードを並べておきます。Thin Ramaze
最近というか、以前から仕事でC#+ASP+AJAX+Oracleしかやってない。Rubyの仕事がしたいです。
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
ブラウザを変えた訳でもないのに Rankomic のデザインがずれていた。なんだろこれ。
今回は動的にFactoryを生成しています。 るびまの添削記事からパクりました。 module FactoryMethod class IDCard def initialize(str) @owner = str end def use "#{@owner}のカードを使います" end end class Factory def create(str) create_product(str)…
IDCardとIDCardFactoryは強い依存関係にある。 しかも型が無いため抽象クラスのようなものは必要ない。 それらを考慮するとこうしてもいいかも。 module FactoryMethod module Factory def create(*arg) product = new(*arg) puts product.owner product end…
なにやら最近盛り上がってますね。 結局のところ好き嫌いあるのが当たり前なんだし、 争うだけ無駄ですよね。でも、それぞれの意見を 聞いてみるのは楽しいと思う。 ただ、PHPしかできない人がPHPをバカにされて、 反論するのはどうかと思う。その他の技術も…
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…
単純移植 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 その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:…
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…
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 …
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 ">" }…
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 …
標準ライブラリを使ってみました。 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, :…
所謂ラッパーですね。まずは単純に移植。継承の場合 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…
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。サンプルプログラムを単純に移植してみます。 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言語で学ぶデザインパターン入門」の サンプルプログラムを…
を読んでいます。gc.c (obj->as.basic.flags & FL_MARK) こんなソースを見かけるが、どんな意味があるんだろう? flagsのままじゃダメなのかな? FL_MARK(0x3f)より上位ビットをどうにかするため? (0x40)で割った時の余り? どんな状況なんだろ?プログラム…