Skip to content

Instantly share code, notes, and snippets.

@grosscol
Created July 27, 2015 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grosscol/97de675fdd5ac339077a to your computer and use it in GitHub Desktop.
Save grosscol/97de675fdd5ac339077a to your computer and use it in GitHub Desktop.
+        terms = characterization_terms
         Sufia.config.fits_to_desc_mapping.each_pair do |k, v|
-          if terms.has_key?(k)
-            # coerce to array to remove a conditional
-            terms[k] = [terms[k]] unless terms[k].is_a? Array
-            terms[k].each do |term_value|
-              proxy_term = self.send(v)
-              if proxy_term.kind_of?(Array)
-                proxy_term << term_value unless proxy_term.include?(term_value)
-              else
-                # these are single-valued terms which cannot be appended to
-                self.send("#{v}=", term_value)
-              end
+          next unless terms.key?(k)
+          Array.wrap(terms[k]).each do |term_value|
+            proxy_term = send(v)
+            if proxy_term.is_a?(Array)
+              proxy_term << term_value unless proxy_term.include?(term_value)
+            else
+              # these are single-valued terms which cannot be appended to
+              send("#{v}=", term_value)
             end
           end

Not sure if the following lines are equivalent. Does Array.wrap ignore values that are array's themselves?

terms[k] = [terms[k]] unless terms[k].is_a? Array
Array.wrap(terms[k]).each do |term_value|
@mjgiarlo
Copy link

Array.wrap(x) returns x if x is already an array and otherwise returns [x]. it never returns [[x]].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment