Class: Object

Inherits:
BasicObject
Defined in:
lib/aspectory.rb

Instance Method Summary collapse

Instance Method Details

#meta_def(name, &block) ⇒ Object



47
48
49
# File 'lib/aspectory.rb', line 47

def meta_def(name, &block)
  meta_eval { define_method(name, &block) }
end

#meta_eval(&block) ⇒ Object



43
44
45
# File 'lib/aspectory.rb', line 43

def meta_eval(&block)
  metaclass.instance_eval(&block)
end

#metaclassObject



39
40
41
# File 'lib/aspectory.rb', line 39

def metaclass
  class << self; self end
end

#tapObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/aspectory.rb', line 19

def tap
  if block_given?
    yield self
    self
  else
    Class.new {
      instance_methods.each { |m| undef_method(m) unless m.to_s =~ /__/ }
    
      def initialize(target)
        @target = target
      end
    
      def method_missing(sym, *args, &block)
        @target.send(sym, *args, &block)
        @target
      end
    }.new(self)
  end
end

#try(sym, *args, &block) ⇒ Object



15
16
17
# File 'lib/aspectory.rb', line 15

def try(sym, *args, &block)
  respond_to?(sym) ? send(sym, *args, &block) : nil
end