Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Use Hash#fetch instead of Hash#[] to resolve type errors #1286

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

tk0miya
Copy link
Contributor

@tk0miya tk0miya commented Oct 18, 2024

135 -> 47

Note: Hash#fetch raises KeyError. So we need to merge this carefully. I'm okay to divide this PR to smaller ones.

@@ -46,7 +46,7 @@ def collect_changes(request)

changes[path] ||= []
request[:params][:contentChanges].each do |change|
changes[path] << Services::ContentChange.new(
changes.fetch(path) << Services::ContentChange.new(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel a bit strange about the combination of Hash#fetch and Array#<<...

when singleton_method
methods = factory.definition_builder.build_singleton(type_name).methods

if singleton_method == :new
methods[:new] || methods[:initialize]
methods[:new] || methods.fetch(:initialize)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is also a bit strange. The left hand is #[], but the right hand is #fetch. It's a little difficult to understand the behavior for me.

@tk0miya tk0miya changed the title refactor: Use Hash#[] to resolve type errors refactor: Use Hash#fetch instead of Hash#[] to resolve type errors Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant