Module: MetaTools
- Defined in:
- lib/meta_tools.rb
Instance Method Summary collapse
-
#class_def(name, &blk) ⇒ Object
Defines an instance method within a class.
-
#class_send(meth, *args, &blk) ⇒ Object
Send a method to the class.
-
#meta_class ⇒ Class
Returns the metaclass of the object.
-
#meta_def(name, &blk) ⇒ Object
Adds methods to a meta_class.
-
#meta_eval(&blk) ⇒ Object
Evaluate a block within the instance of the meta_class.
-
#meta_exec(*args, &blk) ⇒ Object
Evaluate a block within the instance of the meta_class.
-
#meta_methods ⇒ Object
Returns an Array of methods defined only within this Object.
-
#meta_send(meth, *args, &blk) ⇒ Object
Send a method to the meta_class.
-
#metaclass ⇒ Object
The hidden singleton lurks behind everyone.
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_class ⇒ Class
Returns the metaclass of the object.
11 12 13 |
# File 'lib/meta_tools.rb', line 11 def 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 (name, &blk) { 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 (&blk) .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 (*args, &blk) .instance_exec(*args, &blk) end |
#meta_methods ⇒ Object
Returns an Array of methods defined only within this Object.
36 37 38 |
# File 'lib/meta_tools.rb', line 36 def 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 (meth, *args, &blk) .send(meth, *args, &blk) end |
#metaclass ⇒ Object
The hidden singleton lurks behind everyone
3 4 5 6 |
# File 'lib/meta_tools.rb', line 3 def warn "[DEPRECATION] `metaclass` will be deprecated in 0.3.0. Please use `meta_class` instead." end |