Skip to content

Instantly share code, notes, and snippets.

@xn
Last active September 20, 2019 16:22
Show Gist options
  • Save xn/503fb34f3c674f14234d1563fd4190e6 to your computer and use it in GitHub Desktop.
Save xn/503fb34f3c674f14234d1563fd4190e6 to your computer and use it in GitHub Desktop.
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