Module: MetaProgramming::Class

Defined in:
lib/meta_programming/class.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
# File 'lib/meta_programming/class.rb', line 3

def self.included(base)
  raise 'This module may only be included in class Class' unless base.name == 'Class'
end

Instance Method Details

#blank_slate(opts = {}) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/meta_programming/class.rb', line 17

def blank_slate(opts={})
  opts[:except] = opts[:except] ? (opts[:except].is_a?(Array) ? opts[:except] : [opts[:except]]) : []
  exceptions =  opts[:except].map(&:to_s)
  matchers = exceptions.map{|ex| "^#{ex.gsub(/\?/, '\?')}$" }
  matchers += ['^method_missing', '^respond_to'] unless opts[:all]
  matchers << '^__'
  matchers << '^object_id$'
  regexp = Regexp.new(matchers.join('|'))
  instance_methods.each do |m|
    undef_method m unless regexp.match(m.to_s)
  end
end

#dynamic_proxy(target, opts = {}, &block) ⇒ Object

def cast_proxy(target_klass, opts={}, &block)

  matcher = lambda{|sym| target_klass.method_defined?(sym) && sym}
  define_ghost_method(matcher) {|sym, *args| block.call }
end


13
14
15
# File 'lib/meta_programming/class.rb', line 13

def dynamic_proxy(target, opts={}, &block)

end