module ThreeD module Once def self.included(base) base.extend(ClassMethods) end module ClassMethods def once(*ids) # Auch Array kann übergeben werde ids = ids.first if ids.first.is_a?(Array) ids.each do |id| id = id.to_s self.instance_eval do alias_method "__#{id}", id define_method(id) do |*args| ident_name = *args.hash.to_i # Use @once_cache[] key_name = "#{id}_#{ident_name}_#{self.id}".gsub(/[^a-zA-Z0-9_@]/, '') @once_cache ||= {} if @once_cache[key_name].nil? @once_cache[key_name] = self.send("__#{id}", *args) end return @once_cache[key_name] end end end end end end end