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, **kwargs, &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, **kwargs, &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 35 36 37 38 |
# File 'lib/sleeping_king_studios/tools/object_tools.rb', line 23 def apply base, proc, *args, **kwargs, &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 begin if kwargs.empty? base.send temporary_method_name, *args, &block else base.send temporary_method_name, *args, **kwargs, &block end # if-else ensure .send :remove_method, temporary_method_name if temporary_method_name && defined?(temporary_method_name) end end |
#eigenclass(object) ⇒ Class Also known as: metaclass
Returns the object’s eigenclass.
45 46 47 |
# File 'lib/sleeping_king_studios/tools/object_tools.rb', line 45 def eigenclass object class << object; self; end end |