lib/rgen/array_extensions.rb in rgen-0.4.1 vs lib/rgen/array_extensions.rb in rgen-0.4.2

- old
+ new

@@ -9,15 +9,23 @@ compact.inject([]) { |r,e| r | ( (o=e.send(method)).is_a?(Array) ? o : [o] ) } end def method_missing(m, *args) super unless size == 0 or compact.any?{|e| e.is_a? RGen::MetamodelBuilder::MMBase} - compact.inject([]) { |r,e| + # use an array to build the result to achiev similar ordering + result = [] + inResult = {} + compact.each do |e| if e.is_a? RGen::MetamodelBuilder::MMBase - r | ( (o=e.send(m)).is_a?(Array) ? o : [o] ) + ((o=e.send(m)).is_a?(Array) ? o : [o] ).each do |v| + next if inResult[v.object_id] + inResult[v.object_id] = true + result << v + end else raise StandardError.new("Trying to call a method on an array element not a RGen MMBase") end - }.compact + end + result.compact end end \ No newline at end of file