Module: Object::ObjectExtensions

Included in:
Object
Defined in:
lib/ragweed/utils.rb

Instance Method Summary collapse

Instance Method Details

#meta_def(name, &blk) ⇒ Object



9
# File 'lib/ragweed/utils.rb', line 9

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

#meta_eval(&blk) ⇒ Object



8
# File 'lib/ragweed/utils.rb', line 8

def meta_eval(&blk) metaclass.instance_eval &blk; end

#metaclassObject

Every object has a “singleton” class, which you can think of as the class (ie, 1.metaclass =~ Fixnum) — but that you can modify and extend without fucking up the actual class.



7
# File 'lib/ragweed/utils.rb', line 7

def metaclass; class << self; self; end; end

#mymethodsObject

This is from Topher Cyll’s Stupd IRB tricks



21
22
23
# File 'lib/ragweed/utils.rb', line 21

def mymethods
  (self.methods - self.class.superclass.methods).sort
end

#through(meth, *args) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/ragweed/utils.rb', line 12

def through(meth, *args)
    if respond_to? meth
        send(meth, *args)
    else
        self
    end
end

#try(meth, *args) ⇒ Object



10
# File 'lib/ragweed/utils.rb', line 10

def try(meth, *args); send(meth, *args) if respond_to? meth; end