Skip to content

Instantly share code, notes, and snippets.

@kmandreza
Created January 12, 2013 04:27
Show Gist options
  • Save kmandreza/4516092 to your computer and use it in GitHub Desktop.
Save kmandreza/4516092 to your computer and use it in GitHub Desktop.
Refactor a method
def method_4(array)
results = []
array.each do |num|
if num % 2 == 0
results << num
end
end
return results
end
#Refactored
def method_4(array)
array.select {|y| y%2 == 0}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment