Class: Object

Inherits:
BasicObject
Defined in:
lib/starrez_api/object.rb

Overview

Much props to _why and his (poignant) guide This code can originally be found at viewsourcecode.org/why/hacking/seeingMetaclassesClearly.html

Instance Method Summary collapse

Instance Method Details

#class_def(name, &blk) ⇒ Object

Defines an instance method within a class



16
17
18
# File 'lib/starrez_api/object.rb', line 16

def class_def name, &blk
	class_eval { define_method name, &blk }
end

#meta_def(name, &blk) ⇒ Object

Adds methods to a metaclass



11
12
13
# File 'lib/starrez_api/object.rb', line 11

def meta_def name, &blk
	meta_eval { define_method name, &blk }
end

#meta_eval(&blk) ⇒ Object



8
# File 'lib/starrez_api/object.rb', line 8

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

#metaclassObject

The hidden singleton lurks behind everyone



7
# File 'lib/starrez_api/object.rb', line 7

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