Skip to content

Instantly share code, notes, and snippets.

@mitio
Created October 21, 2013 15:06
Show Gist options
  • Save mitio/7085418 to your computer and use it in GitHub Desktop.
Save mitio/7085418 to your computer and use it in GitHub Desktop.
Bad example of implementing http://2013.fmi.ruby.bg/challenges/2
def homogenize(items)
arr_with_integers = []
arr_with_rational = []
arr_with_float = []
arr_with_strings = []
arr_with_symbols = []
arr_with_hash = []
arr_with_array = []
arr_nil_class = []
arr_with_classes = []
arr_true_class = []
arr_false_class = []
return items if items.empty?
items.each do |elements|
arr_with_integers << elements if elements.is_a? Integer
arr_with_rational << elements if elements.is_a? Rational
arr_with_float << elements if elements.is_a? Float
arr_with_strings << elements if elements.is_a? String
arr_with_symbols << elements if elements.is_a? Symbol
arr_with_hash << elements if elements.is_a? Hash
arr_with_array << elements if elements.is_a? Array
arr_nil_class << elements if elements.is_a? NilClass
arr_with_classes << elements if elements.is_a? Class
arr_false_class << elements if elements.is_a? FalseClass
arr_true_class << elements if elements.is_a? TrueClass
end
arr = []
arr << arr_with_integers << arr_with_symbols << arr_with_hash
arr << arr_with_float << arr_with_rational << arr_with_strings
arr << arr_with_array << arr_nil_class << arr_with_classes
arr << arr_false_class << arr_true_class
arr.delete_if { |elements| elements.empty? }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment