mutant
mutant copied to clipboard
Add mutation `foo[bar] || baz` → `foo.fetch(bar, baz)`
I see you have added the following suggestion to my code:
- @cache[name] ||= main[name]
+ @cache[name] ||= main.fetch(name)
I'm not sure why I would rather use fetch over the basic [].
Is there a link to a style guide for this preference or I guess any mutant preference really? (e.g. https://github.com/styleguide/ruby or https://github.com/bbatsov/ruby-style-guide)
I'd like to read up on this. Wonder if it is possible to have a rubocop type preference system for the mutations.
@kbrock #fetch makes more sense there over #[] if the key is guaranteed to be present. I think that supersedes the style aspect. Also FYI this PR is not an implementation of the issue you're talking about.
Wonder if it is possible to have a rubocop type preference system for the mutations
I plan to build this as a third party extension for mutant when I have time. I can tell you now though that @mbj is not interested in any preference system.
I plan to build this as a third party extension for mutant when I have time. I can tell you now though that @mbj is not interested in any preference system.
Not unless I've a comercial reason to do so. I'm fine to refactor mutants internals to support these as extensions, if the mutant code base benefits from this change (and AFAIK it will). I've discussing the API details with @backus in channel.
To answer my question: http://stackoverflow.com/questions/16569409/fetch-vs-when-working-with-hashes and http://devblog.avdi.org/2009/03/16/go-fetch/
and lol - yes, makes sense that mbj doesn't want a preference system