Module: MetaTools

Defined in:
lib/meta_tools.rb

Instance Method Summary collapse

Instance Method Details

#class_def(name, &blk) ⇒ Object

Defines an instance method within a class



41
42
43
# File 'lib/meta_tools.rb', line 41

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

#class_send(meth, *args, &blk) ⇒ Object

Send a method to the class



46
47
48
# File 'lib/meta_tools.rb', line 46

def class_send(meth, *args, &blk)
  self.class.send(meth, *args, &blk)
end

#meta_classClass

Returns the metaclass of the object.

Returns:

  • (Class)

    the metaclass



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

def meta_class
  class << self; self; end
end

#meta_def(name, &blk) ⇒ Object

Adds methods to a meta_class



31
32
33
# File 'lib/meta_tools.rb', line 31

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

#meta_eval(&blk) ⇒ Object

Evaluate a block within the instance of the meta_class



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

def meta_eval(&blk)
  meta_class.instance_eval(&blk)
end

#meta_exec(*args, &blk) ⇒ Object

Evaluate a block within the instance of the meta_class



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

def meta_exec(*args, &blk)
  meta_class.instance_exec(*args, &blk)
end

#meta_methodsObject

Returns an Array of methods defined only within this Object.



36
37
38
# File 'lib/meta_tools.rb', line 36

def meta_methods
  self.class.instance_methods - Object.instance_methods
end

#meta_send(meth, *args, &blk) ⇒ Object

Send a method to the meta_class



26
27
28
# File 'lib/meta_tools.rb', line 26

def meta_send(meth, *args, &blk)
  meta_class.send(meth, *args, &blk)
end

#metaclassObject

The hidden singleton lurks behind everyone



3
4
5
6
# File 'lib/meta_tools.rb', line 3

def metaclass
  warn "[DEPRECATION] `metaclass` will be deprecated in 0.3.0. Please use `meta_class` instead."
  meta_class
end