lib/procemon/mpatch/array.rb in procemon-0.5.0 vs lib/procemon/mpatch/array.rb in procemon-0.6.1
- old
+ new
@@ -97,11 +97,11 @@
alias :contains_element_of_class? :contain_element_of_class?
alias :has_element_of_class? :contain_element_of_class?
# generate params structure from array
- # *args => {:args,:opts}
+ # *args => [:opts,:args]
def params_separation
options= self.map { |element|
if element.class == Hash
element
@@ -109,32 +109,41 @@
}.uniq - [ nil ]
#options.each{|e| self.delete(e) }
arguments= self.dup - options
options= Hash[*options]
- return {
- arguments: arguments,
- args: arguments,
- options: options,
- opts: options
- }
+ return [options,arguments]
end
alias :separate_params :params_separation
alias :process_params :params_separation
# generate params structure from array
- # *args - options {}
- def extract_options!
- options= self.map { |element|
- if element.class == Hash
+ # return_array
+ def extract_class! class_name
+
+ if class_name.class != Class
+ raise ArgumentError, "parameter must be a class name"
+ end
+
+ return_value= self.map { |element|
+ if element.class == class_name
element
end
}.uniq - [ nil ]
- options.each{|e| self.delete(e) }
- return Hash[*options]
+ return_value.each{|e| self.delete(e) }
+
+ return return_value
+
end
+ alias :cut_class! :extract_class!
- alias :get_options! :extract_options!
+ # generate params structure from array
+ # *args - options {}
+ def extract_options!
+ options= self.extract_class! Hash
+ return Hash[*options]
+ end
+ alias :extract_hash! :extract_options!
end
\ No newline at end of file