Class: Rex::Transformer
- Inherits:
-
Object
- Object
- Rex::Transformer
- Defined in:
- lib/rex/transformer.rb
Overview
Transformer - more than meets the eye!
This class, aside from having a kickass name, is responsible for translating object instances of one or more types into a single list instance of one or more types. This is useful for translating object instances that be can either strings or an array of strings into an array of strings, for instance. It lets you make things take a uniform structure in an abstract manner.
Class Method Summary collapse
-
.transform(src_instance, dst_class, supported_classes, target = nil) ⇒ Object
Translates the object instance supplied in src_instance to an instance of dst_class.
Class Method Details
.transform(src_instance, dst_class, supported_classes, target = nil) ⇒ Object
Translates the object instance supplied in src_instance to an instance of dst_class. The dst_class parameter’s instance must support the << operator. An example call to this method looks something like:
Transformer.transform(string, Array, [ String ], target)
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rex/transformer.rb', line 25 def Transformer.transform(src_instance, dst_class, supported_classes, target = nil) dst_instance = dst_class.new if (src_instance.kind_of?(Array)) src_instance.each { |src_inst| Transformer.transform_single(src_inst, dst_instance, supported_classes, target) } elsif (!src_instance.kind_of?(NilClass)) Transformer.transform_single(src_instance, dst_instance, supported_classes, target) end return dst_instance end |