Permalink
Browse files

Revert "Replace internal uses of each with for"

This reverts commit 6a60ffb.

Read this Twitter thread for details:
https://twitter.com/mikec/status/387994418969452545
  • Loading branch information...
1 parent c1141b9 commit a5aaf321fcdf40a576d3794aed5921322b87163a @sferik committed Oct 9, 2013
View
4 lib/twitter/base.rb
@@ -26,7 +26,7 @@ def from_response(response={})
#
# @param attrs [Array, Symbol]
def attr_reader(*attrs)
- for attr in attrs
+ attrs.each do |attr|
define_attribute_method(attr)
define_predicate_method(attr)
end
@@ -46,7 +46,7 @@ def object_attr_reader(klass, key1, key2=nil)
#
# @param attrs [Array, Symbol]
def uri_attr_reader(*attrs)
- for uri_key in attrs
+ attrs.each do |uri_key|
array = uri_key.to_s.split("_")
index = array.index("uri")
array[index] = "url"
View
4 lib/twitter/client.rb
@@ -16,7 +16,7 @@ class Client
# @param options [Hash]
# @return [Twitter::Client]
def initialize(options={})
- for key, value in options
+ options.each do |key, value|
send(:"#{key}=", value)
end
yield self if block_given?
@@ -55,7 +55,7 @@ def credentials?
# @raise [Twitter::Error::ConfigurationError] Error is raised when
# supplied twitter credentials are not a String or Symbol.
def validate_credential_type!
- for credential, value in credentials
+ credentials.each do |credential, value|
next if value.nil?
raise(Error::ConfigurationError, "Invalid #{credential} specified: #{value.inspect} must be a string or symbol.") unless value.is_a?(String) || value.is_a?(Symbol)
end
View
4 lib/twitter/cursor.rb
@@ -50,7 +50,7 @@ def initialize(attrs, key, klass, client, request_method, path, options)
# @return [Enumerator]
def each(start = 0, &block)
return to_enum(:each) unless block_given?
- for element in Array(@collection[start..-1])
+ Array(@collection[start..-1]).each do |element|
yield element
end
unless last?
@@ -90,7 +90,7 @@ def fetch_next_page
def set_attrs(attrs)
@attrs = attrs
- for element in Array(attrs[@key])
+ Array(attrs[@key]).each do |element|
@collection << (@klass ? @klass.new(element) : element)
end
end
View
2 lib/twitter/enumerable.rb
@@ -5,7 +5,7 @@ module Enumerable
# @return [Enumerator]
def each(start = 0, &block)
return to_enum(:each) unless block_given?
- for element in Array(@collection[start..-1])
+ Array(@collection[start..-1]).each do |element|
yield element
end
self
View
2 lib/twitter/rest/api/utils.rb
@@ -221,7 +221,7 @@ def merge_users!(hash, users)
def collect_user_ids_and_screen_names(users)
user_ids, screen_names = [], []
- for user in users.flatten
+ users.flatten.each do |user|
case user
when Integer
user_ids << user
View
2 lib/twitter/rest/request/multipart_with_file.rb
@@ -7,7 +7,7 @@ class MultipartWithFile < Faraday::Middleware
CONTENT_TYPE = 'Content-Type'
def call(env)
- for key, value in env[:body]
+ env[:body].each do |key, value|
if value.respond_to?(:to_io)
env[:body][key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path)
end
View
2 lib/twitter/streaming/response.rb
@@ -19,7 +19,7 @@ def on_headers_complete(headers)
end
def on_body(data)
- for line in @tokenizer.extract(data)
+ @tokenizer.extract(data).each do |line|
next if line.empty?
@block.call(JSON.parse(line, :symbolize_names => true))
end
View
4 spec/twitter/error_spec.rb
@@ -27,9 +27,9 @@
end
end
- for status, exception in Twitter::Error.errors
+ Twitter::Error.errors.each do |status, exception|
- for body in [nil, "error", "errors"]
+ [nil, "error", "errors"].each do |body|
context "when HTTP status is #{status} and body is #{body.inspect}" do
before do
body_message = '{"' + body + '":"Client Error"}' unless body.nil?

2 comments on commit a5aaf32

@mikesea

👍

@sferik
Owner

@mikesea Thanks for raising this issue. I learned something new. 😄

Please sign in to comment.