module MetaTools

Public Instance Methods

class_def(name, &blk) click to toggle source

Defines an instance method within a class

# File lib/meta_tools.rb, line 41
def class_def(name, &blk)
  class_eval { define_method(name, &blk) }
end
class_send(meth, *args, &blk) click to toggle source

Send a method to the class

# File lib/meta_tools.rb, line 46
def class_send(meth, *args, &blk)
  self.class.send(meth, *args, &blk)
end
meta_class() click to toggle source

Returns the metaclass of the object.

@return [Class] the metaclass

# File lib/meta_tools.rb, line 11
def meta_class
  class << self; self; end
end
meta_def(name, &blk) click to toggle source

Adds methods to a meta_class

# File lib/meta_tools.rb, line 31
def meta_def(name, &blk)
  meta_eval { define_method(name, &blk) }
end
meta_eval(&blk) click to toggle source

Evaluate a block within the instance of the meta_class

# File lib/meta_tools.rb, line 16
def meta_eval(&blk)
  meta_class.instance_eval(&blk)
end
meta_exec(*args, &blk) click to toggle source

Evaluate a block within the instance of the meta_class

# File lib/meta_tools.rb, line 21
def meta_exec(*args, &blk)
  meta_class.instance_exec(*args, &blk)
end
meta_methods() click to toggle source

Returns an Array of methods defined only within this Object.

# File lib/meta_tools.rb, line 36
def meta_methods
  self.class.instance_methods - Object.instance_methods
end
meta_send(meth, *args, &blk) click to toggle source

Send a method to the meta_class

# File lib/meta_tools.rb, line 26
def meta_send(meth, *args, &blk)
  meta_class.send(meth, *args, &blk)
end
metaclass() click to toggle source

The hidden singleton lurks behind everyone

# 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