Last active
December 18, 2018 15:34
-
-
Save serradura/35fdd4842f40b21dbe92dbee216a9c4d to your computer and use it in GitHub Desktop.
Exemplo de rake task numa abordagem Procedural |> Funcional (Rubyconf Brasil 2018)
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
ArgAsNumber = -> (args) do | |
-> key { args[key].to_f } | |
end | |
CalculateTaskArgumentsWith = -> (operator) do | |
-> (task, args) do | |
arg_as_number = ArgAsNumber.(args) | |
puts [:a, :b].map(&arg_as_number).reduce(&operator) | |
end | |
end | |
desc 'adds two numbers' | |
task :sum, [:a, :b], &CalculateTaskArgumentsWith.(:+) | |
desc 'subtract two numbers.' | |
task :sub, [:a, :b], &CalculateTaskArgumentsWith.(:-) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment