# = StarFrame::Updatable -- 更新モジュール

module StarFrame #:nodoc:
  # = 更新モジュール
  # 任意のタイミングで内容を更新できるようにするモジュール。
  # 
  # クラスの定義内で、updateクラスメソッドを使用して実際の更新処理を定義する。
  # 
  # == Example
  #   class Sprite
  #     include Updatable
  #     update do
  #       # イベント定義
  #     end
  #   end
  module Updatable
    #:stopdoc:
    def self.included klass
      klass.extend ClassMethods
    end
    #:startdoc:
    
    # 更新する。
    def update
      updated
    end
    alias call update
    
    def updated #:nodoc:
    end
    
    module ClassMethods
      private
      # 更新イベントを定義する
      # 
      # == Example
      #   update do
      #     # 更新イベント定義
      #   end
      def update &block
        raise ArgumentError unless block
        define_method :updated, &block
      end
    end
  end
end
