Created
June 19, 2010 19:49
-
-
Save psfblair/445217 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def distance(*args) | |
| flattened = args.flatten | |
| if flattened.length == 3 | |
| hash_arg = flattened.pop | |
| raise ArgumentError unless hash_arg.respond_to?(:each_key) | |
| flattened << hash_arg[:to][0] | |
| flattened << hash_arg[:to][1] | |
| end | |
| final_args = flattened.select{|number| number.respond_to?(:integer?) } | |
| raise ArgumentError unless final_args.length == 2 || final_args.length == 4 | |
| return measure_distance(*final_args) | |
| end | |
| def measure_distance(first_x, first_y, second_x=0, second_y=0) | |
| x = first_x - second_x | |
| y = first_y - second_y | |
| return Math.sqrt((x*x) + (y*y)) | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment