• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

methoparaに触発されてDIコンテナを作成してみました。コンストラクタインジェクションとプロパティインジェクションをサポートしています。

   1  require 'object_injection'
   2  
   3  class Juicer
   4    attr_reader :fruit
   5  
   6    def initialize fruit
   7      @fruit = fruit
   8    end
   9  end
  10  
  11  class Fruit
  12  end
  13  
  14  container = ObjectInjection::Container.new
  15  container.add Juicer
  16  container.add Fruit
  17  
  18  juicer = container.get :Juicer
  19  p juicer.fruit # => #<Fruit:0x00000001059aa0>

詳細は、 http://github.com/takai/object_injection/ をどうぞ。

posted by Png takai on Thu 26 Mar 2009 at 10:59

Comments:

or Preview
Social Bookmarks
  • Delicious
  • B_entry1379
  • Clip_16_12_w
Services from s21g
twpro(ツイプロ)
Twitterプロフィールを快適検索
地価2009
土地の値段を調べてみよう
MyRestaurant
自分だけのレストラン手帳
Formula
ブログに数式を埋め込める数式コミュニティ