Module: SleepingKingStudios::Tools::ObjectTools
- Extended by:
- ObjectTools
- Included in:
- ObjectTools
- Defined in:
- lib/sleeping_king_studios/tools/object_tools.rb
Overview
Low-level tools for working with objects.
Instance Method Summary collapse
-
#apply(base, proc, *args, &block) ⇒ Object
Takes a proc or lambda and invokes it with the given object as receiver, with any additional arguments or block provided.
-
#eigenclass(object) ⇒ Class
(also: #metaclass)
Returns the object’s eigenclass.
Instance Method Details
#apply(base, proc, *args, &block) ⇒ Object
Takes a proc or lambda and invokes it with the given object as receiver, with any additional arguments or block provided.
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/sleeping_king_studios/tools/object_tools.rb', line 23 def apply base, proc, *args, &block temporary_method_name = :__sleeping_king_studios_tools_object_tools_temporary_method_for_applying_proc__ = class << base; self; end .send :define_method, temporary_method_name, &proc value = base.send temporary_method_name, *args, &block .send :remove_method, temporary_method_name value end |
#eigenclass(object) ⇒ Class Also known as: metaclass
Returns the object’s eigenclass.
41 42 43 |
# File 'lib/sleeping_king_studios/tools/object_tools.rb', line 41 def eigenclass object class << object; self; end end |