May 2018
Intermediate to advanced
412 pages
9h 3m
English
Our parse_args function is waving two red flags. First, it contains conditional logic. Second, it is too long. Let’s split it up.
| | def parse_args(argv) do |
| | OptionParser.parse(argv, switches: [ help: :boolean], |
| | aliases: [ h: :help ]) |
| | |> elem(1) |
| | |> args_to_internal_representation() |
| | end |
| | |
| | def args_to_internal_representation([user, project, count]) do |
| | { user, project, String.to_integer(count) } |
| | end |
| | |
| | def args_to_internal_representation([user, project]) do |
| | { user, project, @default_count } |
| | end |
| | |
| | def args_to_internal_representation(_) do # bad arg or --help |
| | :help |
| | end |
And run the tests:
| | issues$ mix test |
| | ...... |
| | |
| | Finished ... |
Read now
Unlock full access