Skip to content

Commit

Permalink
Revert "Replace internal uses of each with for"
Browse files Browse the repository at this point in the history
This reverts commit 6a60ffb.

Read this Twitter thread for details:
https://twitter.com/mikec/status/387994418969452545
  • Loading branch information
sferik committed Oct 9, 2013
1 parent c1141b9 commit a5aaf32
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions lib/twitter/base.rb
Expand Up @@ -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
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/client.rb
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/twitter/cursor.rb
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/enumerable.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/api/utils.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/rest/request/multipart_with_file.rb
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/twitter/streaming/response.rb
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/twitter/error_spec.rb
Expand Up @@ -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?
Expand Down

2 comments on commit a5aaf32

@mikesea
Copy link

@mikesea mikesea commented on a5aaf32 Oct 9, 2013

Choose a reason for hiding this comment

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

👍

@sferik
Copy link
Owner Author

@sferik sferik commented on a5aaf32 Oct 9, 2013

Choose a reason for hiding this comment

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

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

Please sign in to comment.