Class: Class
Overview
Provides object remapping in new - that is, lets new return an object different from the new one that was requested.
Constant Summary collapse
- @@new_remap =
{}
Class Method Summary collapse
-
.remap_new_object(o, r) ⇒ Object
remaps the original object to a different object to be returned by new.
Instance Method Summary collapse
-
#allows_object_remapping_in_new ⇒ Object
redefines the class’ new method to be able to return a different object.
Class Method Details
.remap_new_object(o, r) ⇒ Object
remaps the original object to a different object to be returned by new
145 146 147 |
# File 'lib/eymiha.rb', line 145 def self.remap_new_object(o,r) @@new_remap[o] = r end |
Instance Method Details
#allows_object_remapping_in_new ⇒ Object
redefines the class’ new method to be able to return a different object
150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/eymiha.rb', line 150 def allows_object_remapping_in_new self.class_eval <<EOS class<<self alias old_new new def new(*args,&block) obj = old_new(*args,&block) Class.new_remap.delete(obj) || obj end end EOS end |