Why might you use #each instead of for/in?

Technology CommunityCategory: RubyWhy might you use #each instead of for/in?
VietMX Staff asked 3 years ago

It’s the “Ruby way” – an example of how Ruby defines methods that mimic natural language concepts. Iterator methods such as #each read more naturally. #each is a block so it defines a new variable scope. for/in depends on the existence of #each which implies that #each is a more fundamental aspect of the language.