Module: Kernel

Defined in:
lib/core_ext/kernel.rb

Instance Method Summary collapse

Instance Method Details

#blank_context(*args, &block) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/core_ext/kernel.rb', line 2

def blank_context(*args, &block)
  ivars = args.extract_options!
  
  args.push(/(^__)|instance_/)
  
  klass = Class.new do
    instance_methods.each do |m|
      undef_method(m) unless args.any? { |pattern| m =~ pattern }
    end
  end
  
  klass.class_eval(&block) if block_given?
  instance = klass.new
  ivars.each { |key, value| instance.instance_variable_set("@#{key}", value) }
  instance
end