Module: ThreadImmutable::ClassMethods

Defined in:
lib/wakame/util.rb

Instance Method Summary collapse

Instance Method Details

#thread_immutable_methods(*args) ⇒ Object



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/wakame/util.rb', line 122

def thread_immutable_methods(*args)
  return if args.empty?
  
  args.each { |n|
    # Proc can not be passed a block due to 1.8's limitation. The following will work in 1.9.
    #um = instance_method(n) || next
    #define_method(n) { |*args, &blk|
    #  thread_check
    #  um.bind(self).call(*args, &blk)
    #}

    if method_defined?(n)
      alias_method "#{n}_no_thread_check", n.to_sym
      
      eval <<-__E__
      def #{n}(*args, &blk)
        thread_check
        #{n}_no_thread_check(*args, &blk)
      end
      __E__
    end
  }
end