incubator-deltacloud-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mfoj...@redhat.com
Subject [PATCH core 5/5] Replaced collect and select with inject
Date Tue, 19 Oct 2010 13:36:03 GMT
From: Michal Fojtik <mfojtik@redhat.com>

---
 client/lib/base_object.rb |    7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/client/lib/base_object.rb b/client/lib/base_object.rb
index 02967ae..ddd1b9f 100644
--- a/client/lib/base_object.rb
+++ b/client/lib/base_object.rb
@@ -119,7 +119,7 @@ module DeltaCloud
       private
 
       def search_for_method(name)
-        @objects.select { |o| o[:method_name] == "#{name}" }.first
+        @objects.detect { |o| o[:method_name] == "#{name}" }
       end
 
     end
@@ -153,7 +153,10 @@ module DeltaCloud
       end
 
       def actions
-        @objects.select {|o| o[:type].eql?(:action_link) }.collect { |o| [o[:rel], o[:href]]
}
+        @objects.inject([]) do |result, item|
+          result << [item[:rel], item[:href]] if item[:type].eql?(:action_link)
+          result
+        end
       end
 
       def action_urls
-- 
1.7.2.3


Mime
View raw message