From: Tadayoshi Funaba Date: 1998-07-06T00:44:31+09:00 Subject: [ruby-list:8634] Re: [ruby-dev:3197] Re: once function ふなばです。 ちょっと手を加えました。適切でないところがあるかもしれませんが、ひとま ず考えていたことはできそうかなと思っています。 # once.rb: Written by Tadayoshi Funaba 1998 # $Id: once.rb,v 1.2 1998/07/04 13:25:48 tadf Exp tadf $ class Module def once(*ids) for id in ids module_eval <<" end" alias_method :__#{id}__, #{id} def #{id.id2name}(*args, &block) def self.#{id.id2name}(*args, &block); @__#{id}__ end @__#{id}__ = __#{id}__(*args, &block) end end end end private :once def once_class_method(*ids) for id in ids module_eval <<" end" class << #{self.name} once #{id} end end end end private :once_class_method end --Tadayoshi Funaba