Last active
September 20, 2019 16:22
-
-
Save xn/503fb34f3c674f14234d1563fd4190e6 to your computer and use it in GitHub Desktop.
This file contains 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
require 'set' | |
def figure_it_out(procs, **params) | |
params_provided = params.keys.to_set | |
procs = procs.each_with_object({}) {|proc, lookup| lookup[proc.parameters.transpose[1].to_set] = proc} | |
procs[params_provided][**params] | |
rescue NoMethodError | |
raise "Unknown set of params, slacker" | |
end | |
volumes = [] | |
volumes << -> (length:, width:, depth:) { | |
length * width * depth | |
} | |
volumes << -> (radius:, height:) { | |
3.14 * radius * radius * height | |
} | |
volumes << -> (side:) { | |
side * side * side | |
} | |
figure_it_out(volumes, side: 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment