auto_pilot 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,50 @@
1
+ module AutoPilot
2
+ class << self
3
+ attr_accessor :configuration
4
+ end
5
+
6
+ def self.configure
7
+ self.configuration ||= Config.new
8
+ yield configuration
9
+ configuration
10
+ end
11
+
12
+ class Config
13
+ attr_accessor :data
14
+
15
+ def initialize(data = {})
16
+ @data = {}
17
+ update(data)
18
+ end
19
+
20
+ def update(data)
21
+ data.each do |key, value|
22
+ self[key.to_sym] = value
23
+ end
24
+ end
25
+
26
+ def [](key)
27
+ @data[key.to_sym]
28
+ end
29
+
30
+ def []=(key, value)
31
+ @data[key.to_sym] = value
32
+ end
33
+
34
+ # def keys
35
+ # @data.keys
36
+ # end
37
+
38
+ # def to_hash
39
+ # @data
40
+ # end
41
+
42
+ def method_missing(sym, *args)
43
+ if sym.to_s =~ /(.+)=$/
44
+ self[Regexp.last_match(1)] = args.first
45
+ else
46
+ self[sym]
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ require 'nokogiri'
2
+ module AutoPilot
3
+ class DocumentParser
4
+ attr_reader :doc, :question_id, :answer_id
5
+ def initialize(doc, question_id, answer_id)
6
+ @doc = Nokogiri::HTML(doc)
7
+ @question_id = question_id
8
+ @answer_id = answer_id
9
+ end
10
+
11
+ def title_html
12
+ doc.css(xml_map[:h1]).inner_html
13
+ end
14
+
15
+ def title_text
16
+ doc.css(xml_map[:h1]).text
17
+ end
18
+
19
+ def question_html
20
+ doc.css(xml_map[:question]).inner_html
21
+ end
22
+
23
+ def question_text
24
+ doc.css(xml_map[:question]).text # you can also call inner_html for semantic formatting
25
+ end
26
+
27
+ def answer_html
28
+ doc.css(xml_map[:answer]).inner_html
29
+ end
30
+
31
+ def answer_text
32
+ doc.css(xml_map[:answer]).text
33
+ end
34
+
35
+ private
36
+
37
+ def xml_map
38
+ @xml_map ||= {
39
+ h1: '#question-header h1 .question-hyperlink',
40
+ question: '#question .post-text',
41
+ answer: "#answer-#{answer_id} .post-text"
42
+ }
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'template_helper'
2
+ module AutoPilot
3
+ class HtmlConverter
4
+ include AutoPilot::TemplateHelper
5
+ attr_reader :doc, :h1_tag, :question, :answer
6
+
7
+ DEFAULT_BLOG_FOLDER = './blog'
8
+
9
+ def initialize(doc)
10
+ @h1_tag = doc.title_html
11
+ @question = doc.question_html
12
+ @answer = doc.answer_html
13
+ make_folder_if_doesnt_exist
14
+ write_file_to_disk(AutoPilot.configuration.folder, :html)
15
+ end
16
+
17
+ private
18
+
19
+ def to_html(html)
20
+ html
21
+ end
22
+
23
+ def delimiter
24
+ '<hr />'
25
+ end
26
+
27
+ def html_template
28
+ @html ||= <<-EOS
29
+ #{h1_tag}
30
+ #{question}
31
+ #{delimiter}
32
+ #{answer}
33
+ EOS
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,51 @@
1
+ require 'reverse_markdown'
2
+ require_relative 'template_helper'
3
+
4
+ module AutoPilot
5
+ class MarkdownConverter
6
+ include AutoPilot::TemplateHelper
7
+ attr_reader :doc, :h1_tag, :question, :answer
8
+
9
+ DEFAULT_BLOG_FOLDER = './stackoverflow'
10
+
11
+ def initialize(doc)
12
+ @h1_tag = to_markdown doc.title_html
13
+ @question = to_markdown doc.question_html
14
+ @answer = to_markdown doc.answer_html
15
+ make_folder_if_doesnt_exist
16
+ write_file_to_disk(AutoPilot.configuration.folder, :md)
17
+ end
18
+
19
+ private
20
+
21
+ def to_markdown(html)
22
+ ReverseMarkdown.convert html
23
+ end
24
+
25
+ def md_template
26
+ @markdown ||= <<-BLOCK.unindent
27
+ #{front_matter unless AutoPilot.configuration.disable_front_matter}
28
+ #{h1_tag}
29
+ #{question}
30
+ #{delimiter}
31
+ #{answer}
32
+ BLOCK
33
+ end
34
+
35
+ def delimiter
36
+ '--------------------------------------- '
37
+ end
38
+
39
+ def front_matter
40
+ <<-BLOCK.unindent
41
+ ---
42
+ layout: post
43
+ title: "#{h1_tag.strip}"
44
+ description: ""
45
+ category:
46
+ tags: []
47
+ ---
48
+ BLOCK
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,51 @@
1
+ require 'httparty'
2
+ require_relative 'url_formatter'
3
+ require_relative 'util/log'
4
+
5
+ module AutoPilot
6
+ class Request
7
+ include HTTParty
8
+
9
+ def self.fetch(url, options = {})
10
+ error unless url
11
+ new(url, options).document
12
+ end
13
+
14
+ def self.error
15
+ Log.red 'invalid url'
16
+ end
17
+
18
+ attr_reader :url, :options, :document, :error
19
+
20
+ def initialize(url, options = {})
21
+ @url, @options = AutoPilot::URLFormatter.default_to_http(url), options
22
+ @document = get_document(url)
23
+ end
24
+
25
+ def get_document(url)
26
+ response = self.class.get(url, options)
27
+ throttle
28
+ log_response(url, response)
29
+ response
30
+ rescue => error
31
+ Log.red "request failed for #{url} #{error}"
32
+ false
33
+ end
34
+
35
+ private
36
+
37
+ def throttle
38
+ sleep(AutoPilot.configuration.throttle || 3)
39
+ end
40
+
41
+ def log_response(url, response)
42
+ code = response.code
43
+ if code != 200
44
+ @error = code
45
+ Log.red "request failure trying to download #{url}, status #{code}"
46
+ else
47
+ Log.green "- downloading #{url}"
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,38 @@
1
+ module AutoPilot
2
+ module TemplateHelper
3
+ def file_name(post_title)
4
+ prefix = Time.now.to_s.split(' ').first # TODO: simplify
5
+ suffix = post_title.gsub(' ', '-').downcase.strip
6
+ "#{prefix}-#{suffix}"
7
+ end
8
+
9
+ def parameterize(string, sep = '-')
10
+ # replace accented chars with their ascii equivalents
11
+ # parameterized_string = transliterate(string)
12
+ # Turn unwanted chars into the separator
13
+ string.gsub!(/[^a-z0-9\-_]+/i, sep)
14
+ unless sep.nil? || sep.empty?
15
+ re_sep = Regexp.escape(sep)
16
+ # No more than one of the separator in a row.
17
+ string.gsub!(/#{re_sep}{2,}/, sep)
18
+ # Remove leading/trailing separator.
19
+ string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
20
+ end
21
+ string.downcase
22
+ end
23
+
24
+ def make_folder_if_doesnt_exist
25
+ system 'mkdir', '-p', AutoPilot.configuration.folder
26
+ end
27
+
28
+ def write_file_to_disk(folder = AutoPilot.configuration.folder, type)
29
+ new_file = file_name(h1_tag)
30
+ sanitized_file_name = parameterize(new_file)
31
+ File.open("#{folder}/#{sanitized_file_name}.#{type}", 'w') do |file|
32
+ method = "#{type}_template"
33
+ file.write(send(method))
34
+ Log.green "- added file ./#{folder}/#{sanitized_file_name}.#{type}"
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,22 @@
1
+
2
+ AutoPilot.configure do |config|
3
+ # string - a stackoverflow username
4
+ config.user = 'username'
5
+ # string - where to put markdown and html files
6
+ config.folder = 'stackoverflow'
7
+ # array - convert to [:md], [:html], or both eg [:md, :html]
8
+ config.format = [:md]
9
+ # boolean - prevent frontmatter from being added to markdown files
10
+ config.disable_front_matter = false
11
+ # integer - max pages when crawling paginated answers on your user page
12
+ # config.max_pages = 50
13
+ config.max_pages = 2
14
+ # string or nil - your application key (optional, allows for more requests)
15
+ config.key = nil
16
+ # integer - time to wait between http requests (optional, eg 3 is 3 seconds)
17
+ config.throttle = 3
18
+
19
+ # TODO: support date confiugrations
20
+ # hash - retrieve questions and answers within a date range eg { start: '2000-01-00', end: '2015-03-05' }
21
+ # config.date = { start: '2000-01-00', end: Time.now.to_s.split(' ').first }
22
+ end
@@ -0,0 +1,8 @@
1
+ module AutoPilot
2
+ module URLFormatter
3
+ def default_to_http(url)
4
+ url[/(^http:\/\/|^https:\/\/)/] ? url : "http://#{url}"
5
+ end
6
+ module_function :default_to_http
7
+ end
8
+ end
@@ -0,0 +1,41 @@
1
+ require 'logger'
2
+ system 'mkdir', '-p', 'log'
3
+
4
+ module AutoPilot
5
+ class Log < Logger
6
+ class << self
7
+ attr_accessor :message
8
+
9
+ def out(text)
10
+ $stdout.write text
11
+ end
12
+
13
+ def colorize(text, color_code)
14
+ $stdout.write "\e[#{color_code}m#{text}\e[0m\n"
15
+ end
16
+
17
+ def red(text)
18
+ @message = text
19
+ colorize(text, 31)
20
+ logger.error text
21
+ end
22
+
23
+ def yellow(text)
24
+ @message = text
25
+ colorize(text, 33)
26
+ end
27
+
28
+ def green(text)
29
+ @message = text
30
+ colorize(text, 32)
31
+ logger.info text
32
+ end
33
+
34
+ private
35
+
36
+ def logger
37
+ @logger ||= new 'log/auto_pilot.log'
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module AutoPilot
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def unindent
3
+ gsub(/^#{self[/\A\s*/]}/, '')
4
+ end
5
+ end
@@ -0,0 +1,33 @@
1
+ {
2
+ items: [
3
+ {
4
+ badge_counts: {
5
+ bronze: 21,
6
+ silver: 22,
7
+ gold: 0
8
+ },
9
+ account_id: 1529114,
10
+ is_employee: false,
11
+ last_modified_date: 1425342976,
12
+ last_access_date: 1425998136,
13
+ reputation_change_year: 565,
14
+ reputation_change_quarter: 565,
15
+ reputation_change_month: 105,
16
+ reputation_change_week: 50,
17
+ reputation_change_day: 10,
18
+ reputation: 2703,
19
+ creation_date: 1338402941,
20
+ user_type: "registered",
21
+ user_id: 1426788,
22
+ accept_rate: 67,
23
+ location: "Atlanta, GA",
24
+ website_url: "https://github.com/lfender6445",
25
+ link: "http://stackoverflow.com/users/1426788/lfender6445",
26
+ display_name: "lfender6445",
27
+ profile_image: "https://www.gravatar.com/avatar/8b836ad1cd8807ca747fe5c5cf6e1839?s=128&d=identicon&r=PG"
28
+ }
29
+ ],
30
+ has_more: false,
31
+ quota_max: 10000,
32
+ quota_remaining: 9960
33
+ }
@@ -0,0 +1,1469 @@
1
+ <!DOCTYPE html>
2
+ <html itemscope itemtype="http://schema.org/QAPage">
3
+ <head>
4
+
5
+ <title>ruby - Refactoring an each loop - Stack Overflow</title>
6
+ <link rel="shortcut icon" href="//cdn.sstatic.net/stackoverflow/img/favicon.ico?v=6cd6089ee7f6">
7
+ <link rel="apple-touch-icon image_src" href="//cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png?v=41f6e13ade69">
8
+ <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
9
+ <meta name="twitter:card" content="summary">
10
+ <meta name="twitter:domain" content="stackoverflow.com"/>
11
+ <meta property="og:type" content="website" />
12
+ <meta property="og:image" itemprop="image primaryImageOfPage" content="http://cdn.sstatic.net/stackoverflow/img/apple-touch-icon@2.png?v=ea71a5211a91" />
13
+ <meta name="twitter:title" property="og:title" itemprop="title name" content="Refactoring an each loop" />
14
+ <meta name="twitter:description" property="og:description" itemprop="description" content="This is a bit of a n00b question. I&#39;m trying to figure out how I can refactor a nested each loop like the one below so that I am not declaring extra variables that I won&#39;t need later and so that my..." />
15
+ <meta property="og:url" content="http://stackoverflow.com/questions/28956301/refactoring-an-each-loop"/>
16
+ <link rel="canonical" href="http://stackoverflow.com/questions/28956301/refactoring-an-each-loop" />
17
+
18
+
19
+
20
+ <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
21
+ <script src="//cdn.sstatic.net/Js/stub.en.js?v=de684f918f61"></script>
22
+ <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/stackoverflow/all.css?v=73d7f11addbd">
23
+
24
+ <link rel="alternate" type="application/atom+xml" title="Feed for question &#39;Refactoring an each loop&#39;" href="/feeds/question/28956301">
25
+ <meta name="twitter:app:country" content="US" />
26
+ <meta name="twitter:app:name:iphone" content="Stack Exchange iOS" />
27
+ <meta name="twitter:app:id:iphone" content="871299723" />
28
+ <meta name="twitter:app:url:iphone" content="se-zaphod://stackoverflow.com/questions/28956301/refactoring-an-each-loop" />
29
+ <meta name="twitter:app:name:ipad" content="Stack Exchange iOS" />
30
+ <meta name="twitter:app:id:ipad" content="871299723" />
31
+ <meta name="twitter:app:url:ipad" content="se-zaphod://stackoverflow.com/questions/28956301/refactoring-an-each-loop" />
32
+ <meta name="twitter:app:name:googleplay" content="Stack Exchange Android">
33
+ <meta name="twitter:app:url:googleplay" content="http://stackoverflow.com/questions/28956301/refactoring-an-each-loop">
34
+ <meta name="twitter:app:id:googleplay" content="com.stackexchange.marvin">
35
+ <script>
36
+
37
+ StackExchange.ready(function () {
38
+
39
+ StackExchange.using("snippets", function () {
40
+ StackExchange.snippets.initSnippetRenderer();
41
+ });
42
+
43
+
44
+ StackExchange.using("postValidation", function () {
45
+ StackExchange.postValidation.initOnBlurAndSubmit($('#post-form'), 2, 'answer');
46
+ });
47
+
48
+
49
+ StackExchange.question.init({votesCast:[],canViewVoteCounts:true,totalCommentCount:7,shownCommentCount:5,highlightColor:'#F4A83D',backgroundColor:'#FFF',questionId:28956301});
50
+
51
+ styleCode();
52
+
53
+ StackExchange.realtime.subscribeToQuestion('1', '28956301');
54
+
55
+ });
56
+ </script>
57
+
58
+
59
+ <script>
60
+ StackExchange.ready(function () {
61
+ StackExchange.realtime.init('wss://qa.sockets.stackexchange.com,ws://qa.sockets.stackexchange.com');
62
+ StackExchange.realtime.subscribeToInboxNotifications();
63
+ StackExchange.realtime.subscribeToReputationNotifications('1');
64
+ StackExchange.realtime.subscribeToTopBarNotifications('1');
65
+ });
66
+ </script>
67
+ <script>
68
+ StackExchange.init({"locale":"en","stackAuthUrl":"https://stackauth.com","serverTime":1425963685,"networkMetaHostname":"meta.stackexchange.com","routeName":"Questions/Show","styleCode":true,"enableUserHovercards":true,"snippets":{"enabled":true,"domain":"stacksnippets.net"},"site":{"name":"Stack Overflow","description":"Q&A for professional and enthusiast programmers","isNoticesTabEnabled":true,"recaptchaPublicKey":"6LdchgIAAAAAAJwGpIzRQSOFaO0pU6s44Xt8aTwc","recaptchaAudioLang":"en","enableNewTagCreationWarning":true,"insertSpaceAfterNameTabCompletion":false,"nonAsciiTags":true,"enableSocialMediaInSharePopup":true},"user":{"fkey":"99930b286faac981606961b01079c491","isRegistered":true,"keyboardShortcuts":true,"userType":3,"userId":1426788,"accountId":1529114,"gravatar":"<div class=\"gravatar-wrapper-32\"><img src=\"https://www.gravatar.com/avatar/8b836ad1cd8807ca747fe5c5cf6e1839?s=32&d=identicon&r=PG\" alt=\"\" width=\"32\" height=\"32\"></div>","profileUrl":"http://stackoverflow.com/users/1426788/lfender6445","notificationsUnviewedCount":0,"inboxUnviewedCount":0}});
69
+ StackExchange.using.setCacheBreakers({"js/prettify-full.en.js":"40792bc1651d","js/moderator.en.js":"0e548b869b0d","js/full-anon.en.js":"04d20484f988","js/full.en.js":"f7c13db13eb7","js/wmd.en.js":"1638238fb115","js/third-party/jquery.autocomplete.min.js":"e5f01e97f7c3","js/third-party/jquery.autocomplete.min.en.js":"","js/mobile.en.js":"d96cd4adc9de","js/help.en.js":"5a7b18512b93","js/tageditor.en.js":"c8d06452914a","js/tageditornew.en.js":"b6d97891dbae","js/inline-tag-editing.en.js":"49f7375eb68e","js/revisions.en.js":"6c7265ea9fa1","js/review.en.js":"9b3967d985e1","js/tagsuggestions.en.js":"d1ff9b84abe5","js/post-validation.en.js":"b19ba78d4d2d","js/explore-qlist.en.js":"257ba4cb7b04","js/events.en.js":"2fa54a1ec36c","js/keyboard-shortcuts.en.js":"5187eddee540","js/external-editor.en.js":"3376e2d7516e","js/external-editor.en.js":"3376e2d7516e","js/snippet-javascript.en.js":"49fc6920793f","js/snippet-javascript-codemirror.en.js":"6d1111fb1ed4"});
70
+ StackExchange.using("gps", function() {
71
+ StackExchange.gps.init(true);
72
+ });
73
+ </script>
74
+
75
+
76
+
77
+ </head>
78
+ <body class="question-page new-topbar">
79
+ <noscript><div id="noscript-padding"></div></noscript>
80
+ <div id="notify-container"></div>
81
+ <div id="overlay-header"></div>
82
+ <div id="custom-header"></div>
83
+
84
+
85
+
86
+
87
+ <div class="topbar">
88
+ <div class="topbar-wrapper">
89
+
90
+ <div class="js-topbar-dialog-corral">
91
+
92
+ <div class="topbar-dialog siteSwitcher-dialog dno">
93
+ <div class="header">
94
+ <h3><a href="//stackoverflow.com">current community</a></h3>
95
+ </div>
96
+ <div class="modal-content current-site-container">
97
+ <ul class="current-site">
98
+ <li>
99
+ <div class="related-links">
100
+ <a href="http://chat.stackoverflow.com" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:6 })"
101
+ >chat</a>
102
+ <a href="http://blog.stackoverflow.com" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:7 })"
103
+ >blog</a>
104
+ <a href="/users/logout" class="js-gps-track" data-gps-track="site_switcher.click({ item_type:8 })"
105
+ >log out</a>
106
+ </div>
107
+
108
+
109
+
110
+
111
+ <a href="//stackoverflow.com"
112
+ class="current-site-link site-link js-gps-track"
113
+ data-id="1"
114
+ data-gps-track="
115
+ site_switcher.click({ item_type:3 })">
116
+ <div class="site-icon favicon favicon-stackoverflow" title="Stack Overflow"></div>
117
+ Stack Overflow
118
+ </a>
119
+
120
+ </li>
121
+ <li class="related-site">
122
+ <div class="L-shaped-icon-container">
123
+ <span class="L-shaped-icon"></span>
124
+ </div>
125
+
126
+
127
+
128
+
129
+
130
+ <a href="http://meta.stackoverflow.com"
131
+ class="site-link js-gps-track"
132
+ data-id="552"
133
+ data-gps-track="
134
+ site.switch({ target_site:552, item_type:3 }),
135
+ site_switcher.click({ item_type:4 })">
136
+ <div class="site-icon favicon favicon-stackoverflowmeta" title="Meta Stack Overflow"></div>
137
+ Meta Stack Overflow
138
+ </a>
139
+
140
+ </li>
141
+ <li class="related-site">
142
+ <div class="L-shaped-icon-container">
143
+ <span class="L-shaped-icon"></span>
144
+ </div>
145
+
146
+ <a class="site-link js-gps-track"
147
+ href="//careers.stackoverflow.com?utm_source=stackoverflow.com&utm_medium=site-ui&utm_campaign=multicollider"
148
+ data-gps-track="site_switcher.click({ item_type:9 })"
149
+ >
150
+ <div class="site-icon favicon favicon-careers" title="Stack Overflow Careers"></div>
151
+ Stack Overflow Careers
152
+ </a>
153
+ </li>
154
+ </ul>
155
+ </div>
156
+
157
+ <div class="header" id="your-communities-header">
158
+ <h3>
159
+ <a href="//stackexchange.com/users/1529114/?tab=accounts">your communities</a>
160
+ </h3>
161
+
162
+ <a href="#" id="edit-pinned-sites">edit</a>
163
+ <a href="#" id="cancel-pinned-sites" style="display: none;">cancel</a>
164
+ </div>
165
+ <div class="modal-content" id="your-communities-section">
166
+
167
+ <ul class="my-sites">
168
+ <li>
169
+
170
+
171
+
172
+
173
+ <a href="//stackoverflow.com"
174
+ class="site-link js-gps-track"
175
+ data-id="1"
176
+ data-gps-track="
177
+ site.switch({ target_site:1, item_type:3 }),
178
+ site_switcher.click({ item_type:1 })">
179
+ <div class="site-icon favicon favicon-stackoverflow" title="Stack Overflow"></div>
180
+ Stack Overflow
181
+ <span class="rep-score">2,693</span>
182
+ </a>
183
+
184
+ </li>
185
+ <li>
186
+
187
+
188
+
189
+
190
+ <a href="//apple.stackexchange.com"
191
+ class="site-link js-gps-track"
192
+ data-id="118"
193
+ data-gps-track="
194
+ site.switch({ target_site:118, item_type:3 }),
195
+ site_switcher.click({ item_type:1 })">
196
+ <div class="site-icon favicon favicon-apple" title="Ask Different"></div>
197
+ Ask Different
198
+ <span class="rep-score">128</span>
199
+ </a>
200
+
201
+ </li>
202
+ <li>
203
+
204
+
205
+
206
+
207
+ <a href="//unix.stackexchange.com"
208
+ class="site-link js-gps-track"
209
+ data-id="106"
210
+ data-gps-track="
211
+ site.switch({ target_site:106, item_type:3 }),
212
+ site_switcher.click({ item_type:1 })">
213
+ <div class="site-icon favicon favicon-unix" title="Unix &amp; Linux"></div>
214
+ Unix &amp; Linux
215
+ <span class="rep-score">113</span>
216
+ </a>
217
+
218
+ </li>
219
+ <li>
220
+
221
+
222
+
223
+
224
+ <a href="//music.stackexchange.com"
225
+ class="site-link js-gps-track"
226
+ data-id="240"
227
+ data-gps-track="
228
+ site.switch({ target_site:240, item_type:3 }),
229
+ site_switcher.click({ item_type:1 })">
230
+ <div class="site-icon favicon favicon-music" title="Music: Practice &amp; Theory"></div>
231
+ Music: Practice &amp; Theory
232
+ <span class="rep-score">106</span>
233
+ </a>
234
+
235
+ </li>
236
+ <li>
237
+
238
+
239
+
240
+
241
+ <a href="//programmers.stackexchange.com"
242
+ class="site-link js-gps-track"
243
+ data-id="131"
244
+ data-gps-track="
245
+ site.switch({ target_site:131, item_type:3 }),
246
+ site_switcher.click({ item_type:1 })">
247
+ <div class="site-icon favicon favicon-programmers" title="Programmers"></div>
248
+ Programmers
249
+ <span class="rep-score">105</span>
250
+ </a>
251
+
252
+ </li>
253
+ </ul>
254
+ <div class="pinned-site-editor-container" style="display: none;">
255
+ <input id="js-site-search-txt"
256
+ type="text"
257
+ class="site-filter-input"
258
+ value=""
259
+ placeholder="Add a Stack Exchange community"/>
260
+ <input type="submit" id="pin-site-btn" value="Add" disabled="disabled"/>
261
+ <ul class="js-found-sites found-sites"></ul>
262
+ <ul class="pinned-site-list sortable" data-custom-list="False">
263
+ </ul>
264
+ <input type="submit" value="Save" id="save-pinned-sites-btn" disabled="disabled"/>
265
+ <a href="#" id="reset-pinned-sites">reset to default list</a>
266
+ </div>
267
+ </div>
268
+
269
+ <div class="header">
270
+ <h3><a href="//stackexchange.com/sites">more stack exchange communities</a></h3>
271
+ </div>
272
+ <div class="modal-content">
273
+ <div class="child-content"></div>
274
+ </div>
275
+ </div>
276
+ </div>
277
+
278
+ <div class="network-items">
279
+
280
+ <a href="//stackexchange.com"
281
+ class="topbar-icon icon-site-switcher yes-hover js-site-switcher-button js-gps-track"
282
+ data-gps-track="site_switcher.show"
283
+ title="A list of all 137 Stack Exchange sites">
284
+ <span class="hidden-text">Stack Exchange</span>
285
+ </a>
286
+
287
+ <a href="#"
288
+ class="topbar-icon icon-inbox yes-hover js-inbox-button"
289
+ title="Recent inbox messages">
290
+ <span class="hidden-text">Inbox</span>
291
+ <span class="unread-count" style="display:none"></span>
292
+ </a>
293
+ <a href="#"
294
+ class="topbar-icon icon-achievements yes-hover js-achievements-button "
295
+ data-unread-class=""
296
+ title="Recent achievements: reputation, badges, and privileges earned">
297
+ <span class="hidden-text">Reputation and Badges</span>
298
+ <span class="unread-count" style="display:none">
299
+
300
+ </span>
301
+ </a>
302
+ </div>
303
+
304
+ <div class="topbar-links">
305
+
306
+ <a href="/users/1426788/lfender6445" class="profile-me js-gps-track" data-gps-track="profile_summary.click()">
307
+ <div class="gravatar-wrapper-24" title="lfender6445"><img src="https://www.gravatar.com/avatar/8b836ad1cd8807ca747fe5c5cf6e1839?s=24&d=identicon&r=PG" alt="" width="24" height="24" class="avatar-me js-avatar-me"></div>
308
+ <div class="links-container topbar-flair">
309
+
310
+ <span class="reputation" title="your reputation: 2,693">
311
+ 2,693
312
+ </span>
313
+ <span title="22 silver badges"><span class="badge2"></span><span class="badgecount">22</span></span><span title="21 bronze badges"><span class="badge3"></span><span class="badgecount">21</span></span> </div>
314
+ </a>
315
+ <div class="links-container">
316
+ <span class="topbar-menu-links">
317
+
318
+
319
+
320
+ <a href="/review" title="Review queues - help improve the site">
321
+ review
322
+ </a>
323
+
324
+ <a href="#" class="icon-help js-help-button" title="Help Center and other resources">
325
+ help
326
+ <span class="triangle"></span>
327
+ </a>
328
+ <div class="topbar-dialog help-dialog js-help-dialog dno">
329
+ <div class="modal-content">
330
+ <ul>
331
+ <li>
332
+ <a href="/tour" class="js-gps-track" data-gps-track="help_popup.click({ item_type:1 })">
333
+ Tour
334
+ <span class="item-summary">
335
+ Start here for a quick overview of the site
336
+ </span>
337
+ </a>
338
+ </li>
339
+ <li>
340
+ <a href="/help" class="js-gps-track" data-gps-track="help_popup.click({ item_type:4 })">
341
+ Help Center
342
+ <span class="item-summary">
343
+ Detailed answers to any questions you might have
344
+ </span>
345
+ </a>
346
+ </li>
347
+ <li>
348
+ <a href="//meta.stackoverflow.com" class="js-gps-track" data-gps-track="help_popup.click({ item_type:2 })">
349
+ Meta
350
+ <span class="item-summary">
351
+ Discuss the workings and policies of this site
352
+ </span>
353
+ </a>
354
+ </li>
355
+ </ul>
356
+ </div>
357
+ </div>
358
+
359
+ </span>
360
+ </div>
361
+
362
+ <div class="search-container">
363
+ <form id="search" action="/search" method="get" autocomplete="off">
364
+ <input name="q" type="text" placeholder="search" value="" tabindex="1" autocomplete="off" maxlength="240" />
365
+ </form>
366
+ </div>
367
+
368
+ </div>
369
+ </div>
370
+ </div>
371
+ <script>
372
+ StackExchange.ready(function() { StackExchange.topbar.init(); });
373
+ </script>
374
+
375
+ <div class="container">
376
+ <div id="header">
377
+ <br class="cbt">
378
+ <div id="hlogo">
379
+ <a href="/">
380
+ Stack Overflow
381
+ </a>
382
+ </div>
383
+ <div id="hmenus">
384
+ <div class="nav mainnavs">
385
+ <ul>
386
+ <li class="youarehere"><a id="nav-questions" href="/questions">Questions</a></li>
387
+ <li><a id="nav-tags" href="/tags">Tags</a></li>
388
+ <li><a id="nav-users" href="/users">Users</a></li>
389
+ <li><a id="nav-badges" href="/help/badges">Badges</a></li>
390
+ <li><a id="nav-unanswered" href="/unanswered">Unanswered</a></li>
391
+ </ul>
392
+ </div>
393
+ <div class="nav askquestion">
394
+ <ul>
395
+ <li>
396
+ <a id="nav-askquestion" href="/questions/ask">Ask Question</a>
397
+ </li>
398
+ </ul>
399
+ </div>
400
+ </div>
401
+ </div>
402
+
403
+
404
+
405
+
406
+ <div id="content" class="snippet-hidden">
407
+
408
+
409
+ <div itemscope itemtype="http://schema.org/Question">
410
+ <link itemprop="image" href="//cdn.sstatic.net/stackoverflow/img/apple-touch-icon.png">
411
+ <div id="question-header">
412
+ <h1 itemprop="name"><a href="/questions/28956301/refactoring-an-each-loop" class="question-hyperlink">Refactoring an each loop</a></h1>
413
+ </div>
414
+ <div id="mainbar">
415
+
416
+
417
+
418
+ <div class="question" data-questionid="28956301" id="question">
419
+
420
+ <table>
421
+ <tr>
422
+ <td class="votecell">
423
+
424
+
425
+ <div class="vote">
426
+ <input type="hidden" name="_id_" value="28956301">
427
+ <a class="vote-up-off" title="This question shows research effort; it is useful and clear (click again to undo)">up vote</a>
428
+ <span itemprop="upvoteCount" class="vote-count-post ">0</span>
429
+ <a class="vote-down-off" title="This question does not show any research effort; it is unclear or not useful (click again to undo)">down vote</a>
430
+
431
+ <a class="star-off" href="#" title="This is a favorite question (click again to undo)">favorite</a>
432
+ <div class="favoritecount"><b></b></div>
433
+
434
+ </div>
435
+
436
+ </td>
437
+
438
+ <td class="postcell">
439
+ <div>
440
+ <div class="post-text" itemprop="text">
441
+
442
+ <p>This is a bit of a n00b question. I'm trying to figure out how I can refactor a nested each loop like the one below so that I am not declaring extra variables that I won't need later and so that my code runs quicker.</p>
443
+
444
+ <pre><code>some_array = [["one", 2, 3], ["two", 3, 4], ["three", 4, 5]]
445
+ output = {}
446
+
447
+ some_array.each do |a|
448
+ current_group = []
449
+
450
+ another_array.each do |b|
451
+ current_group &lt;&lt; b if something == true
452
+ end
453
+
454
+ output[a[0]] = current_group
455
+ end
456
+ </code></pre>
457
+
458
+ <p>The <code>output</code> is returned as a hash of arrays. <code>some_array</code> is a nested array where the first element in each sub-array is a string and <code>another_array</code> is an array of hashes.</p>
459
+
460
+ </div>
461
+ <div class="post-taglist">
462
+ <a href="/questions/tagged/ruby" class="post-tag" title="show questions tagged 'ruby'" rel="tag">ruby</a> <a href="/questions/tagged/arrays" class="post-tag" title="show questions tagged 'arrays'" rel="tag">arrays</a> <a href="/questions/tagged/each" class="post-tag" title="show questions tagged 'each'" rel="tag">each</a>
463
+ </div>
464
+ <table class="fw">
465
+ <tr>
466
+ <td class="vt">
467
+ <div class="post-menu"><a href="/q/28956301/1426788" title="short permalink to this question" class="short-link" id="link-post-28956301">share</a><span class="lsep">|</span><a href="/posts/28956301/edit" class="edit-post" title="revise and improve this post">edit</a><span class="lsep">|</span><a href="#"
468
+ class="flag-post-link"
469
+ title="flag this post for serious problems or moderator attention"
470
+ data-postid="28956301">flag</a></div>
471
+ </td>
472
+ <td align="right" class="post-signature">
473
+ <div class="user-info ">
474
+ <div class="user-action-time">
475
+ <a href="/posts/28956301/revisions" title="show all edits to this post">edited <span title="2015-03-10 05:01:11Z" class="relativetime">14 secs ago</span></a>
476
+ </div>
477
+ <div class="user-gravatar32">
478
+
479
+ </div>
480
+ <div class="user-details">
481
+ <br>
482
+
483
+ </div>
484
+ </div> </td>
485
+ <td class="post-signature owner">
486
+ <div class="user-info ">
487
+ <div class="user-action-time">
488
+ asked <span title="2015-03-10 04:41:02Z" class="relativetime">20 mins ago</span>
489
+ </div>
490
+ <div class="user-gravatar32">
491
+ <a href="/users/4139179/acidstealth"><div class="gravatar-wrapper-32"><img src="http://i.stack.imgur.com/cen47.png?s=32&g=1" alt="" width="32" height="32"></div></a>
492
+ </div>
493
+ <div class="user-details">
494
+ <a href="/users/4139179/acidstealth">ACIDSTEALTH</a><br>
495
+ <span class="reputation-score" title="reputation score " dir="ltr">42</span><span title="7 bronze badges"><span class="badge3"></span><span class="badgecount">7</span></span>
496
+ </div>
497
+ </div>
498
+ </td>
499
+ </tr>
500
+ </table>
501
+ </div>
502
+ </td>
503
+ </tr>
504
+
505
+ <tr>
506
+ <td class="votecell"></td>
507
+ <td>
508
+ <div id="comments-28956301" class="comments ">
509
+ <table>
510
+ <tbody data-remaining-comments-count="2"
511
+ data-canpost="true"
512
+ data-cansee="false"
513
+ data-comments-unavailable="false"
514
+ data-addlink-disabled="false">
515
+
516
+
517
+
518
+ <tr id="comment-46165711" class="comment ">
519
+ <td class="comment-actions">
520
+ <table>
521
+ <tbody>
522
+ <tr>
523
+ <td class=" comment-score">
524
+ &nbsp;&nbsp;
525
+ </td>
526
+ <td>
527
+ <a class="comment-up comment-up-off" title="this comment adds something useful to the post">upvote</a>
528
+ </td>
529
+ </tr>
530
+ <tr>
531
+ <td>&nbsp;</td>
532
+ <td>
533
+ <a class="comment-flag" title="Flag this comment for serious problems or moderator attention">flag</a>
534
+ </td>
535
+ </tr>
536
+ </tbody>
537
+ </table>
538
+ </td>
539
+ <td class="comment-text">
540
+ <div style="display: block;" class="comment-body">
541
+ <span class="comment-copy">What is <code>group</code>?</span>
542
+ &ndash;&nbsp;
543
+ <a href="/users/797049/mark-reed"
544
+ title="28655 reputation"
545
+ class="comment-user">Mark Reed</a>
546
+ <span class="comment-date" dir="ltr"><span title="2015-03-10 04:42:43Z" class="relativetime-clean">18 mins ago</span></span>
547
+ <span class="edited-yes" title="this comment was edited 1 time"></span>
548
+ </div>
549
+ </td>
550
+ </tr>
551
+ <tr id="comment-46165724" class="comment ">
552
+ <td class="comment-actions">
553
+ <table>
554
+ <tbody>
555
+ <tr>
556
+ <td class=" comment-score">
557
+ <span title="number of &#39;useful comment&#39; votes received"
558
+ class="cool">1</span>
559
+ </td>
560
+ <td>
561
+ <a class="comment-up comment-up-off" title="this comment adds something useful to the post">upvote</a>
562
+ </td>
563
+ </tr>
564
+ <tr>
565
+ <td>&nbsp;</td>
566
+ <td>
567
+ <a class="comment-flag" title="Flag this comment for serious problems or moderator attention">flag</a>
568
+ </td>
569
+ </tr>
570
+ </tbody>
571
+ </table>
572
+ </td>
573
+ <td class="comment-text">
574
+ <div style="display: block;" class="comment-body">
575
+ <span class="comment-copy">You probably want <a href="http://ruby-doc.org/core-2.2.1/Enumerable.html#method-i-inject" rel="nofollow"><code>.inject</code></a></span>
576
+ &ndash;&nbsp;
577
+ <a href="/users/599436/jon"
578
+ title="5279 reputation"
579
+ class="comment-user">Jon</a>
580
+ <span class="comment-date" dir="ltr"><span title="2015-03-10 04:43:28Z" class="relativetime-clean">17 mins ago</span></span>
581
+ </div>
582
+ </td>
583
+ </tr>
584
+ <tr id="comment-46165755" class="comment ">
585
+ <td class="comment-actions">
586
+ <table>
587
+ <tbody>
588
+ <tr>
589
+ <td class=" comment-score">
590
+ &nbsp;&nbsp;
591
+ </td>
592
+ <td>
593
+ <a class="comment-up comment-up-off" title="this comment adds something useful to the post">upvote</a>
594
+ </td>
595
+ </tr>
596
+ <tr>
597
+ <td>&nbsp;</td>
598
+ <td>
599
+ <a class="comment-flag" title="Flag this comment for serious problems or moderator attention">flag</a>
600
+ </td>
601
+ </tr>
602
+ </tbody>
603
+ </table>
604
+ </td>
605
+ <td class="comment-text">
606
+ <div style="display: block;" class="comment-body">
607
+ <span class="comment-copy">How come your outer loop is not using <code>a</code>?</span>
608
+ &ndash;&nbsp;
609
+ <a href="/users/978917/ruakh"
610
+ title="73684 reputation"
611
+ class="comment-user">ruakh</a>
612
+ <span class="comment-date" dir="ltr"><span title="2015-03-10 04:45:32Z" class="relativetime-clean">15 mins ago</span></span>
613
+ </div>
614
+ </td>
615
+ </tr>
616
+ <tr id="comment-46165793" class="comment ">
617
+ <td class="comment-actions">
618
+ <table>
619
+ <tbody>
620
+ <tr>
621
+ <td class=" comment-score">
622
+ &nbsp;&nbsp;
623
+ </td>
624
+ <td>
625
+ <a class="comment-up comment-up-off" title="this comment adds something useful to the post">upvote</a>
626
+ </td>
627
+ </tr>
628
+ <tr>
629
+ <td>&nbsp;</td>
630
+ <td>
631
+ <a class="comment-flag" title="Flag this comment for serious problems or moderator attention">flag</a>
632
+ </td>
633
+ </tr>
634
+ </tbody>
635
+ </table>
636
+ </td>
637
+ <td class="comment-text">
638
+ <div style="display: block;" class="comment-body">
639
+ <span class="comment-copy">I just edited the code. <code>group</code> is <code>a</code>.</span>
640
+ &ndash;&nbsp;
641
+ <a href="/users/4139179/acidstealth"
642
+ title="42 reputation"
643
+ class="comment-user owner">ACIDSTEALTH</a>
644
+ <span class="comment-date" dir="ltr"><span title="2015-03-10 04:48:04Z" class="relativetime-clean">13 mins ago</span></span>
645
+ </div>
646
+ </td>
647
+ </tr>
648
+ <tr id="comment-46165822" class="comment ">
649
+ <td class="comment-actions">
650
+ <table>
651
+ <tbody>
652
+ <tr>
653
+ <td class=" comment-score">
654
+ &nbsp;&nbsp;
655
+ </td>
656
+ <td>
657
+ <a class="comment-up comment-up-off" title="this comment adds something useful to the post">upvote</a>
658
+ </td>
659
+ </tr>
660
+ <tr>
661
+ <td>&nbsp;</td>
662
+ <td>
663
+ <a class="comment-flag" title="Flag this comment for serious problems or moderator attention">flag</a>
664
+ </td>
665
+ </tr>
666
+ </tbody>
667
+ </table>
668
+ </td>
669
+ <td class="comment-text">
670
+ <div style="display: block;" class="comment-body">
671
+ <span class="comment-copy">what is <code>something</code>?</span>
672
+ &ndash;&nbsp;
673
+ <a href="/users/3001736/amit-joki"
674
+ title="33465 reputation"
675
+ class="comment-user">Amit Joki</a>
676
+ <span class="comment-date" dir="ltr"><span title="2015-03-10 04:49:37Z" class="relativetime-clean">11 mins ago</span></span>
677
+ </div>
678
+ </td>
679
+ </tr>
680
+ </tbody>
681
+ <tfoot>
682
+ <tr>
683
+ <td></td>
684
+ <td class="comment-form">
685
+ <form id="add-comment-28956301"
686
+ class=""
687
+ data-placeholdertext="Use comments to ask for more information or suggest improvements. Avoid answering questions in comments."></form>
688
+ </td>
689
+ </tr>
690
+ </tfoot>
691
+ </table>
692
+ </div>
693
+
694
+ <div id="comments-link-28956301" >
695
+
696
+ <a class="js-add-link comments-link "
697
+ title="Use comments to ask for more information or suggest improvements. Avoid answering questions in comments."
698
+ href=#>add a comment</a><span class="js-link-separator ">&nbsp;|&nbsp;</span>
699
+ <a class="js-show-link comments-link " title="expand to show all comments on this post, or add one of your own" href=# onclick="">show <b>2</b> more comments</a>
700
+ </div>
701
+ </td>
702
+ </tr> </table>
703
+ </div>
704
+
705
+ <div id="answers">
706
+
707
+ <a name="tab-top"></a>
708
+ <div id="answers-header">
709
+ <div class="subheader answers-subheader">
710
+ <h2>
711
+ 1 Answer
712
+ <span style="display:none;" itemprop="answerCount">1</span>
713
+ </h2>
714
+ <div>
715
+ <div id="tabs">
716
+ <a href="/questions/28956301/refactoring-an-each-loop?answertab=active#tab-top" title="Answers with the latest activity first">active</a>
717
+ <a href="/questions/28956301/refactoring-an-each-loop?answertab=oldest#tab-top" title="Answers in the order they were provided">oldest</a>
718
+ <a class="youarehere" href="/questions/28956301/refactoring-an-each-loop?answertab=votes#tab-top" title="Answers with the highest score first">votes</a>
719
+ </div>
720
+ </div>
721
+ </div>
722
+ </div>
723
+
724
+
725
+
726
+
727
+
728
+ <a name="28956353"></a>
729
+ <div id="answer-28956353" class="answer" data-answerid="28956353" itemscope itemtype="http://schema.org/Answer">
730
+ <table>
731
+ <tr>
732
+ <td class="votecell">
733
+
734
+
735
+ <div class="vote">
736
+ <input type="hidden" name="_id_" value="28956353">
737
+ <a class="vote-up-off" title="This answer is useful (click again to undo)">up vote</a>
738
+ <span itemprop="upvoteCount" class="vote-count-post ">0</span>
739
+ <a class="vote-down-off" title="This answer is not useful (click again to undo)">down vote</a>
740
+
741
+
742
+
743
+ </div>
744
+
745
+ </td>
746
+
747
+
748
+
749
+ <td class="answercell">
750
+ <div class="post-text" itemprop="text">
751
+ <p>I can't tell exactly what you're doing from that code - what is <code>group</code>? How does the condition tie <code>some_array</code> and <code>other_array</code> together? But in general, if you want to build a new array or hash, the idiom to reach for is something with <code>inject</code> (a.k.a. <code>reduce</code>). The pattern is this:</p>
752
+
753
+ <pre><code>output = some_array.inject({}) do |partial_output, item|
754
+ ...
755
+ new value of partial_output after this loop iteration
756
+ end
757
+ </code></pre>
758
+ </div>
759
+ <table class="fw">
760
+ <tr>
761
+ <td class="vt">
762
+ <div class="post-menu"><a href="/a/28956353/1426788" title="short permalink to this answer" class="short-link" id="link-post-28956353">share</a><span class="lsep">|</span><a href="/posts/28956353/edit" class="edit-post" title="revise and improve this post">edit</a><span class="lsep">|</span><a href="#"
763
+ class="flag-post-link"
764
+ title="flag this post for serious problems or moderator attention"
765
+ data-postid="28956353">flag</a></div> </td>
766
+
767
+
768
+
769
+ <td align="right" class="post-signature">
770
+
771
+
772
+ <div class="user-info user-hover">
773
+ <div class="user-action-time">
774
+ answered <span title="2015-03-10 04:46:48Z" class="relativetime">14 mins ago</span>
775
+ </div>
776
+ <div class="user-gravatar32">
777
+ <a href="/users/797049/mark-reed"><div class="gravatar-wrapper-32"><img src="https://www.gravatar.com/avatar/5f4f7a23e3d0134123a66015bdc4edd1?s=32&d=identicon&r=PG" alt="" width="32" height="32"></div></a>
778
+ </div>
779
+ <div class="user-details">
780
+ <a href="/users/797049/mark-reed">Mark Reed</a><br>
781
+ <span class="reputation-score" title="reputation score 28655" dir="ltr">28.7k</span><span title="4 gold badges"><span class="badge1"></span><span class="badgecount">4</span></span><span title="35 silver badges"><span class="badge2"></span><span class="badgecount">35</span></span><span title="62 bronze badges"><span class="badge3"></span><span class="badgecount">62</span></span>
782
+ </div>
783
+ </div>
784
+ </td>
785
+ </tr>
786
+ </table>
787
+ </td>
788
+ </tr>
789
+
790
+ <tr>
791
+ <td class="votecell"></td>
792
+ <td>
793
+ <div id="comments-28956353" class="comments dno">
794
+ <table>
795
+ <tbody data-remaining-comments-count="0"
796
+ data-canpost="true"
797
+ data-cansee="false"
798
+ data-comments-unavailable="false"
799
+ data-addlink-disabled="false">
800
+
801
+ <tr><td></td><td></td></tr>
802
+ </tbody>
803
+ <tfoot>
804
+ <tr>
805
+ <td></td>
806
+ <td class="comment-form">
807
+ <form id="add-comment-28956353"
808
+ class=""
809
+ data-placeholdertext="Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”."></form>
810
+ </td>
811
+ </tr>
812
+ </tfoot>
813
+ </table>
814
+ </div>
815
+
816
+ <div id="comments-link-28956353" >
817
+
818
+ <a class="js-add-link comments-link "
819
+ title="Use comments to ask for more information or suggest improvements. Avoid comments like “+1” or “thanks”."
820
+ href=#>add a comment</a><span class="js-link-separator dno">&nbsp;|&nbsp;</span>
821
+ <a class="js-show-link comments-link dno" title="expand to show all comments on this post, or add one of your own" href=# onclick=""></a>
822
+ </div>
823
+ </td>
824
+ </tr> </table>
825
+ </div>
826
+ <a name='new-answer'></a>
827
+ <form id="post-form" action="/questions/28956301/answer/submit" method="post" class="post-form">
828
+ <input type="hidden" id="post-id" value="28956301" />
829
+ <input type="hidden" id="qualityBanWarningShown" name="qualityBanWarningShown" value="false" />
830
+ <input type="hidden" name="referrer" value="http://stackoverflow.com/"/>
831
+ <h2 class="space">Your Answer</h2>
832
+
833
+
834
+
835
+ <script>
836
+ StackExchange.ifUsing("editor", function () {
837
+ StackExchange.using("externalEditor", function () {
838
+ StackExchange.using("snippets", function () {
839
+ StackExchange.snippets.init();
840
+ });
841
+ });
842
+ }, "code-snippets");
843
+ </script>
844
+
845
+
846
+ <script>
847
+ StackExchange.ready(function() {
848
+ initTagRenderer("".split(" "), "".split(" "));
849
+
850
+ StackExchange.using("externalEditor", function() {
851
+ // Have to fire editor after snippets, if snippets enabled
852
+ if (StackExchange.options.snippets.enabled) {
853
+ StackExchange.using("snippets", function() {
854
+ createEditor();
855
+ });
856
+ }
857
+ else {
858
+ createEditor();
859
+ }
860
+ });
861
+
862
+ function createEditor() {
863
+ prepareEditor({
864
+ heartbeatType: 'answer',
865
+ bindNavPrevention: true,
866
+ postfix: "",
867
+ onDemand: false,
868
+ discardSelector: ".discard-answer"
869
+
870
+ });
871
+
872
+
873
+ }
874
+ });
875
+ </script>
876
+
877
+
878
+ <div id="post-editor" class="post-editor">
879
+
880
+ <div style="position: relative;">
881
+ <div class="wmd-container">
882
+ <div id="wmd-button-bar" class="wmd-button-bar"></div>
883
+ <textarea id="wmd-input" class="wmd-input" name="post-text" cols="92" rows="15" tabindex="101" data-min-length=""></textarea>
884
+ </div>
885
+ </div>
886
+
887
+ <div class="fl" style="margin-top: 8px; height:24px;">&nbsp;</div>
888
+ <div id="draft-saved" class="draft-saved community-option fl" style="margin-top: 8px; height:24px; display:none;">draft saved</div>
889
+
890
+ <div id="draft-discarded" class="draft-discarded community-option fl" style="margin-top: 8px; height:24px; display:none;">draft discarded</div>
891
+
892
+ <div class="community-option">
893
+ <input id="communitymode" name="communitymode" type="checkbox" >
894
+ <label for="communitymode" title="Marking an answer community wiki encourages others to edit it by lowering the reputation barrier required to edit. However, you will not gain any upvote reputation from it. This cannot be undone.">community wiki</label>
895
+ </div>
896
+
897
+
898
+ <div id="wmd-preview" class="wmd-preview"></div>
899
+ <div></div>
900
+ <div class="edit-block">
901
+ <input id="fkey" name="fkey" type="hidden" value="99930b286faac981606961b01079c491">
902
+ <input id="author" name="author" type="text">
903
+ </div>
904
+
905
+
906
+
907
+ </div>
908
+ <div style="position: relative;">
909
+
910
+ </div>
911
+
912
+ <div class="form-submit cbt">
913
+ <input id="submit-button" type="submit" value="Post Your Answer" tabindex="110">
914
+ <a href="#" class="discard-answer dno">discard</a>
915
+ </div>
916
+ </form>
917
+
918
+ <script>
919
+ StackExchange.using("inlineEditing", function () {
920
+ StackExchange.inlineEditing.init();
921
+ });
922
+ </script>
923
+
924
+
925
+ <h2 class="bottom-notice" data-loc="1">
926
+ Not the answer you&#39;re looking for? Browse other questions tagged <a href="/questions/tagged/ruby" class="post-tag" title="show questions tagged 'ruby'" rel="tag">ruby</a> <a href="/questions/tagged/arrays" class="post-tag" title="show questions tagged 'arrays'" rel="tag">arrays</a> <a href="/questions/tagged/each" class="post-tag" title="show questions tagged 'each'" rel="tag">each</a> or <a href="/questions/ask">ask your own question</a>. </h2>
927
+ </div>
928
+ </div>
929
+ <div id="sidebar" class="show-votes">
930
+ <div class="module question-stats">
931
+ <table id="qinfo">
932
+ <tr>
933
+ <td>
934
+ <p class="label-key">asked</p>
935
+ </td>
936
+ <td style="padding-left: 10px">
937
+ <p class="label-key" title="2015-03-10 04:41:02Z"><b>today</b></p>
938
+ </td>
939
+ </tr>
940
+ <tr>
941
+ <td>
942
+ <p class="label-key">viewed</p>
943
+ </td>
944
+
945
+ <td style="padding-left: 10px">
946
+ <p class="label-key">
947
+ <b>10 times</b>
948
+ </p>
949
+ </td>
950
+ </tr>
951
+ <tr>
952
+ <td>
953
+ <p class="label-key">active</p>
954
+ </td>
955
+ <td style="padding-left: 10px">
956
+ <p class="label-key"><b><a href="?lastactivity" class="lastactivity-link" title="2015-03-10 05:01:11Z">today</a></b></p>
957
+ </td>
958
+ </tr>
959
+ </table>
960
+ </div>
961
+ <div class="module community-bulletin" data-tracker="cb=1">
962
+ <div class="related">
963
+ <div class="bulletin-title">
964
+ Featured on Meta
965
+ </div>
966
+ <hr />
967
+ <div class="spacer">
968
+ <div class="bulletin-item-type">
969
+ <a href="http://meta.stackoverflow.com/questions/287466/help-improve-the-help-improvement-queue" class="question-hyperlink">
970
+ <div class="favicon favicon-stackoverflowmeta" title="Meta Stack Overflow"></div> </a>
971
+ </div>
972
+ <div class="bulletin-item-content">
973
+ <a href="http://meta.stackoverflow.com/questions/287466/help-improve-the-help-improvement-queue" class="question-hyperlink">Help Improve The Help &amp; Improvement Queue!</a>
974
+ </div>
975
+ <br class="cbt" />
976
+ </div>
977
+ <div class="bulletin-title">
978
+ Hot Meta Posts
979
+ </div>
980
+ <hr />
981
+ <div class="spacer">
982
+ <div class="bulletin-item-type">
983
+ <span title="Vote score (upvotes - downvotes)">8</span>
984
+ </div>
985
+ <div class="bulletin-item-content">
986
+ <a href="http://meta.stackoverflow.com/questions/287662/synonymise-stackoverflowexception-and-stackoverflowerror-to-stackoverflow" class="question-hyperlink">Synonymise [stackoverflowexception] and [stackoverflowerror] to [stackoverflow]</a>
987
+ </div>
988
+ <br class="cbt" />
989
+ </div>
990
+ <div class="spacer">
991
+ <div class="bulletin-item-type">
992
+ <span title="Vote score (upvotes - downvotes)">4</span>
993
+ </div>
994
+ <div class="bulletin-item-content">
995
+ <a href="http://meta.stackoverflow.com/questions/287682/how-to-ask-a-question-when-you-dont-know-what-solutions-are-required" class="question-hyperlink">How to ask a question when you don&#39;t know what solutions are required</a>
996
+ </div>
997
+ <br class="cbt" />
998
+ </div>
999
+ <div class="spacer">
1000
+ <div class="bulletin-item-type">
1001
+ <span title="Vote score (upvotes - downvotes)">8</span>
1002
+ </div>
1003
+ <div class="bulletin-item-content">
1004
+ <a href="http://meta.stackoverflow.com/questions/287650/how-to-partially-answer-my-own-question-protocol" class="question-hyperlink">How to Partially Answer My Own Question: Protocol</a>
1005
+ </div>
1006
+ <br class="cbt" />
1007
+ </div>
1008
+ </div>
1009
+ </div>
1010
+ <script>
1011
+ var ados = ados || {};ados.run = ados.run || [];
1012
+ ados.run.push(function() { ados_add_placement(22,8277,"adzerk264977753",[17,2221]).setZone(45) ; });
1013
+ </script>
1014
+ <div class="everyonelovesstackoverflow" id="adzerk264977753">
1015
+ </div>
1016
+ <div id="hireme">
1017
+ <script>
1018
+ ;(function(e){var a=window.$,p=window.StackExchange,f=100,c="div#hireme,div.hireme",g=decodeURIComponent,i=encodeURIComponent,r=setTimeout,h=document,q,b,m={},l=location.hash;if(l.length>1){l.substr(1).split("&").forEach(function(t){var u=t.split("=");this[g(u[0])]=g(u[1])},m)}b=m.ac||m.accountid||(p&&p.options&&p.options.user&&p.options.user.accountId);if(b){m.ac=b}if(!m.tags){q=a(".post-taglist .post-tag").map(function(){return a(this).text()});if(q.length>0){m.tags=Array.prototype.join.call(q,";")}}if(l==="#large"){m.l=1}if(l==="#abort"){m.abort=1}function j(t){return a(t).html().replace(/\s+/g,"").length>0}function s(){var t=a("#sidebar [id^='adzerk'].everyonelovesstackoverflow");if(t.length===0){return true}return !j(t)}function n(){var t=a(c);if(t.length>0){if(m.l||a("#careersadsdoublehigh").length>0){m.l=1}var v=t.map(function(z,y){return"d="+y.id}).get().join("&");var x=["l","ip","ac","eng","prov","tags","theme"];var u=Object.keys(m).filter(function(y){return x.indexOf(y)!==-1}).map(function(y){return i(y)+"="+i(m[y])}).join("&");if(u){v+="&"+u}var w=h.createElement("script");w.type="text/javascript";w.src=e+(e.indexOf("?")===-1?"?":"&")+v;h.body.appendChild(w)}}function o(){if(s()){d=r(o,f);return}if(m.abort){k()}n()}function k(){clearTimeout(d);a(c).each(function(){var t=a(this);if(!j(t)){var v=t;var u=t.parents(".everyonelovesstackoverflow").first();if(u.length>0){v=u}v.remove()}})}r(k,2000);var d=r(o,f)}).apply(null, ["//clc.stackoverflow.com/j/p"]); </script>
1019
+
1020
+ </div>
1021
+
1022
+
1023
+
1024
+
1025
+ <div class="module sidebar-related">
1026
+ <h4 id="h-related">Related</h4>
1027
+ <div class="related js-gps-related-questions" data-tracker="rq=1">
1028
+ <div class="spacer">
1029
+ <a href="/q/3312412" title="Vote score (upvotes - downvotes)">
1030
+ <div class="answer-votes answered-accepted default">1
1031
+ </div>
1032
+ </a><a href="/questions/3312412/how-to-add-more-than-one-piece-of-data-to-an-array-follow-the-each-method" class="question-hyperlink">How to add more than one piece of data to an array follow the .each method</a>
1033
+ </div>
1034
+ <div class="spacer">
1035
+ <a href="/q/4000713" title="Vote score (upvotes - downvotes)">
1036
+ <div class="answer-votes answered-accepted default">37
1037
+ </div>
1038
+ </a><a href="/questions/4000713/tell-the-end-of-a-each-loop-in-ruby" class="question-hyperlink">Tell the end of a .each loop in ruby</a>
1039
+ </div>
1040
+ <div class="spacer">
1041
+ <a href="/q/4103055" title="Vote score (upvotes - downvotes)">
1042
+ <div class="answer-votes answered-accepted default">5
1043
+ </div>
1044
+ </a><a href="/questions/4103055/ruby-each-logic-question" class="question-hyperlink">Ruby each logic question</a>
1045
+ </div>
1046
+ <div class="spacer">
1047
+ <a href="/q/9329446" title="Vote score (upvotes - downvotes)">
1048
+ <div class="answer-votes answered-accepted extra-large">1379
1049
+ </div>
1050
+ </a><a href="/questions/9329446/for-each-over-an-array-in-javascript" class="question-hyperlink">For-each over an array in JavaScript?</a>
1051
+ </div>
1052
+ <div class="spacer">
1053
+ <a href="/q/9637053" title="Vote score (upvotes - downvotes)">
1054
+ <div class="answer-votes answered-accepted default">3
1055
+ </div>
1056
+ </a><a href="/questions/9637053/loop-within-loop-within-loop-on-ruby-on-rails" class="question-hyperlink">Loop within loop within loop on Ruby on Rails</a>
1057
+ </div>
1058
+ <div class="spacer">
1059
+ <a href="/q/11596879" title="Vote score (upvotes - downvotes)">
1060
+ <div class="answer-votes answered-accepted default">8
1061
+ </div>
1062
+ </a><a href="/questions/11596879/why-does-arrayeach-return-an-array-with-the-same-elements" class="question-hyperlink">Why does Array#each return an array with the same elements?</a>
1063
+ </div>
1064
+ <div class="spacer">
1065
+ <a href="/q/14386493" title="Vote score (upvotes - downvotes)">
1066
+ <div class="answer-votes answered-accepted default">0
1067
+ </div>
1068
+ </a><a href="/questions/14386493/iterating-thru-array-values-using-each-not-working" class="question-hyperlink">Iterating thru array values using $.each not working</a>
1069
+ </div>
1070
+ <div class="spacer">
1071
+ <a href="/q/24270294" title="Vote score (upvotes - downvotes)">
1072
+ <div class="answer-votes answered-accepted default">0
1073
+ </div>
1074
+ </a><a href="/questions/24270294/use-each-on-an-array-to-iterate-over-and-return-the-index-of-greater-values" class="question-hyperlink">Use Each on an array to iterate over and return the index of greater values</a>
1075
+ </div>
1076
+ <div class="spacer">
1077
+ <a href="/q/25676195" title="Vote score (upvotes - downvotes)">
1078
+ <div class="answer-votes default">1
1079
+ </div>
1080
+ </a><a href="/questions/25676195/how-to-rewrite-this-each-loop-in-ruby" class="question-hyperlink">How to rewrite this each loop in ruby?</a>
1081
+ </div>
1082
+ <div class="spacer">
1083
+ <a href="/q/27048100" title="Vote score (upvotes - downvotes)">
1084
+ <div class="answer-votes default">2
1085
+ </div>
1086
+ </a><a href="/questions/27048100/ruby-how-to-speed-up-looping-through-an-each-array" class="question-hyperlink">Ruby - how to speed up looping through an &ldquo;.each&rdquo; array?</a>
1087
+ </div>
1088
+
1089
+ </div>
1090
+ </div>
1091
+
1092
+ <div id="hot-network-questions" class="module">
1093
+ <h4>
1094
+ <a href="//stackexchange.com/questions?tab=hot"
1095
+ class="js-gps-track"
1096
+ data-gps-track="posts_hot_network.click({ item_type:1, location:11 })">
1097
+ Hot Network Questions
1098
+ </a>
1099
+ </h4>
1100
+ <ul>
1101
+ <li >
1102
+ <div class="favicon favicon-photo" title="Photography Stack Exchange"></div><a href="http://photo.stackexchange.com/questions/60861/what-does-the-paper-folded-slightly-up-symbol-mean-in-lightroom" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:61 }); posts_hot_network.click({ item_type:2, location:11 })">
1103
+ What does the &quot;paper folded slightly up&quot; symbol mean in Lightroom?
1104
+ </a>
1105
+
1106
+ </li>
1107
+ <li >
1108
+ <div class="favicon favicon-travel" title="Travel Stack Exchange"></div><a href="http://travel.stackexchange.com/questions/44350/who-was-this-persistent-person-at-shanghai-airport" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:273 }); posts_hot_network.click({ item_type:2, location:11 })">
1109
+ Who was this persistent person at Shanghai airport?
1110
+ </a>
1111
+
1112
+ </li>
1113
+ <li >
1114
+ <div class="favicon favicon-programmers" title="Programmers Stack Exchange"></div><a href="http://programmers.stackexchange.com/questions/275756/what-should-be-loggers-position-in-the-parameter-list" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:131 }); posts_hot_network.click({ item_type:2, location:11 })">
1115
+ what should be logger&#39;s position in the parameter list
1116
+ </a>
1117
+
1118
+ </li>
1119
+ <li >
1120
+ <div class="favicon favicon-puzzling" title="Puzzling Stack Exchange"></div><a href="http://puzzling.stackexchange.com/questions/10000/a-semi-truck-weighing-exactly-10-000-pounds" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:559 }); posts_hot_network.click({ item_type:2, location:11 })">
1121
+ A semi truck weighing exactly 10,000 pounds
1122
+ </a>
1123
+
1124
+ </li>
1125
+ <li >
1126
+ <div class="favicon favicon-academia" title="Academia Stack Exchange"></div><a href="http://academia.stackexchange.com/questions/41341/equal-author-contribution" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:415 }); posts_hot_network.click({ item_type:2, location:11 })">
1127
+ Equal author contribution
1128
+ </a>
1129
+
1130
+ </li>
1131
+ <li class="dno js-hidden">
1132
+ <div class="favicon favicon-worldbuilding" title="Worldbuilding Stack Exchange"></div><a href="http://worldbuilding.stackexchange.com/questions/11541/on-a-generation-ship-how-to-handle-the-dead" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:579 }); posts_hot_network.click({ item_type:2, location:11 })">
1133
+ On a generation ship, how to handle the dead?
1134
+ </a>
1135
+
1136
+ </li>
1137
+ <li class="dno js-hidden">
1138
+ <div class="favicon favicon-workplace" title="The Workplace Stack Exchange"></div><a href="http://workplace.stackexchange.com/questions/42537/how-to-prevent-a-psychologically-fragile-person-from-harming-a-team" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:423 }); posts_hot_network.click({ item_type:2, location:11 })">
1139
+ How to prevent a psychologically fragile person from harming a team?
1140
+ </a>
1141
+
1142
+ </li>
1143
+ <li class="dno js-hidden">
1144
+ <div class="favicon favicon-physics" title="Physics Stack Exchange"></div><a href="http://physics.stackexchange.com/questions/169275/can-the-brain-detect-the-passage-of-a-neutrino" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:151 }); posts_hot_network.click({ item_type:2, location:11 })">
1145
+ Can the brain detect the passage of a neutrino?
1146
+ </a>
1147
+
1148
+ </li>
1149
+ <li class="dno js-hidden">
1150
+ <div class="favicon favicon-judaism" title="Mi Yodeya"></div><a href="http://judaism.stackexchange.com/questions/56254/how-to-select-the-spot-for-my-sukkah" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:248 }); posts_hot_network.click({ item_type:2, location:11 })">
1151
+ How to select the spot for my Sukkah
1152
+ </a>
1153
+
1154
+ </li>
1155
+ <li class="dno js-hidden">
1156
+ <div class="favicon favicon-skeptics" title="Skeptics Stack Exchange"></div><a href="http://skeptics.stackexchange.com/questions/26978/is-fluoride-an-ingredient-in-prozac-and-rat-poison" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:212 }); posts_hot_network.click({ item_type:2, location:11 })">
1157
+ Is fluoride an ingredient in Prozac and rat poison?
1158
+ </a>
1159
+
1160
+ </li>
1161
+ <li class="dno js-hidden">
1162
+ <div class="favicon favicon-mathoverflow" title="MathOverflow"></div><a href="http://mathoverflow.net/questions/199532/length-comparison-on-negatively-curved-surfaces" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:504 }); posts_hot_network.click({ item_type:2, location:11 })">
1163
+ length comparison on negatively curved surfaces
1164
+ </a>
1165
+
1166
+ </li>
1167
+ <li class="dno js-hidden">
1168
+ <div class="favicon favicon-worldbuilding" title="Worldbuilding Stack Exchange"></div><a href="http://worldbuilding.stackexchange.com/questions/11572/volume-efficient-team-sports-for-a-narrow-environment" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:579 }); posts_hot_network.click({ item_type:2, location:11 })">
1169
+ Volume-efficient team sports for a narrow environment
1170
+ </a>
1171
+
1172
+ </li>
1173
+ <li class="dno js-hidden">
1174
+ <div class="favicon favicon-vi" title="Vi and Vim Stack Exchange"></div><a href="http://vi.stackexchange.com/questions/2455/what-additional-features-do-gvim-and-or-macvim-offer-compared-to-vim-inside-a-te" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:599 }); posts_hot_network.click({ item_type:2, location:11 })">
1175
+ What additional features do gVim and/or MacVim offer compared to Vim inside a terminal emulator?
1176
+ </a>
1177
+
1178
+ </li>
1179
+ <li class="dno js-hidden">
1180
+ <div class="favicon favicon-english" title="English Language &amp; Usage Stack Exchange"></div><a href="http://english.stackexchange.com/questions/232563/what-would-you-call-that-feeling-of-something-crawling-on-the-body" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:97 }); posts_hot_network.click({ item_type:2, location:11 })">
1181
+ What would you call that feeling of something crawling on the body
1182
+ </a>
1183
+
1184
+ </li>
1185
+ <li class="dno js-hidden">
1186
+ <div class="favicon favicon-codegolf" title="Programming Puzzles &amp; Code Golf Stack Exchange"></div><a href="http://codegolf.stackexchange.com/questions/47566/adding-numbers-with-regex" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:200 }); posts_hot_network.click({ item_type:2, location:11 })">
1187
+ Adding Numbers with Regex
1188
+ </a>
1189
+
1190
+ </li>
1191
+ <li class="dno js-hidden">
1192
+ <div class="favicon favicon-salesforce" title="Salesforce Stack Exchange"></div><a href="http://salesforce.stackexchange.com/questions/68728/efficiency-of-list-size-0-vs-list-isempty" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:459 }); posts_hot_network.click({ item_type:2, location:11 })">
1193
+ Efficiency of List.size() &gt; 0 vs. !List.isEmpty()
1194
+ </a>
1195
+
1196
+ </li>
1197
+ <li class="dno js-hidden">
1198
+ <div class="favicon favicon-judaism" title="Mi Yodeya"></div><a href="http://judaism.stackexchange.com/questions/56243/sitting-during-laining-accd-to-r-abadi" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:248 }); posts_hot_network.click({ item_type:2, location:11 })">
1199
+ Sitting During Laining accd to R Abadi
1200
+ </a>
1201
+
1202
+ </li>
1203
+ <li class="dno js-hidden">
1204
+ <div class="favicon favicon-movies" title="Movies &amp; TV Stack Exchange"></div><a href="http://movies.stackexchange.com/questions/31940/why-did-dr-manhattan-choose-the-hydrogen-atom-for-the-symbol-on-his-forehead" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:367 }); posts_hot_network.click({ item_type:2, location:11 })">
1205
+ Why did Dr. Manhattan choose the hydrogen atom for the symbol on his forehead?
1206
+ </a>
1207
+
1208
+ </li>
1209
+ <li class="dno js-hidden">
1210
+ <div class="favicon favicon-superuser" title="Super User"></div><a href="http://superuser.com/questions/887266/found-new-malware-not-detected-by-antivirus-how-to-evaluate-the-threat" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:3 }); posts_hot_network.click({ item_type:2, location:11 })">
1211
+ Found new malware not detected by antivirus. How to evaluate the threat?
1212
+ </a>
1213
+
1214
+ </li>
1215
+ <li class="dno js-hidden">
1216
+ <div class="favicon favicon-english" title="English Language &amp; Usage Stack Exchange"></div><a href="http://english.stackexchange.com/questions/232672/what-do-you-call-excessive-snow" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:97 }); posts_hot_network.click({ item_type:2, location:11 })">
1217
+ What do you call excessive snow?
1218
+ </a>
1219
+
1220
+ </li>
1221
+ <li class="dno js-hidden">
1222
+ <div class="favicon favicon-electronics" title="Electrical Engineering Stack Exchange"></div><a href="http://electronics.stackexchange.com/questions/158957/how-do-diodes-and-capacitors-reduce-crossover-distortion" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:135 }); posts_hot_network.click({ item_type:2, location:11 })">
1223
+ How do diodes and capacitors reduce Crossover distortion?
1224
+ </a>
1225
+
1226
+ </li>
1227
+ <li class="dno js-hidden">
1228
+ <div class="favicon favicon-codereview" title="Code Review Stack Exchange"></div><a href="http://codereview.stackexchange.com/questions/83668/calculate-next-working-day" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:196 }); posts_hot_network.click({ item_type:2, location:11 })">
1229
+ Calculate next working day
1230
+ </a>
1231
+
1232
+ </li>
1233
+ <li class="dno js-hidden">
1234
+ <div class="favicon favicon-diy" title="Home Improvement Stack Exchange"></div><a href="http://diy.stackexchange.com/questions/61686/why-does-my-drill-bit-destroy-the-screw-head" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:73 }); posts_hot_network.click({ item_type:2, location:11 })">
1235
+ Why does my drill bit destroy the screw head?
1236
+ </a>
1237
+
1238
+ </li>
1239
+ <li class="dno js-hidden">
1240
+ <div class="favicon favicon-scifi" title="Science Fiction &amp; Fantasy Stack Exchange"></div><a href="http://scifi.stackexchange.com/questions/83358/in-episode-iv-a-new-hope-why-did-obi-wan-wait-till-luke-showed-up-then-let-va" class="js-gps-track" data-gps-track="site.switch({ item_type:11, target_site:186 }); posts_hot_network.click({ item_type:2, location:11 })">
1241
+ In episode IV, A New Hope, why did Obi-wan wait till Luke showed up, then let Vader kill him?
1242
+ </a>
1243
+
1244
+ </li>
1245
+ </ul>
1246
+
1247
+ <a href="#"
1248
+ class="show-more js-show-more js-gps-track"
1249
+ data-gps-track="posts_hot_network.click({ item_type:3, location:11 })">
1250
+ more hot questions
1251
+ </a>
1252
+ </div>
1253
+ </div>
1254
+
1255
+ <div id="feed-link">
1256
+ <div id="feed-link-text">
1257
+ <a href="/feeds/question/28956301" title="feed of this question and its answers">
1258
+ <span class="feed-icon"></span>question feed
1259
+ </a>
1260
+ </div>
1261
+ </div> <script>
1262
+ StackExchange.ready(function(){$.get('/posts/28956301/ivc/d30d');});
1263
+ </script>
1264
+ <noscript>
1265
+ <div><img src="/posts/28956301/ivc/d30d" class="dno" alt="" width="0" height="0"></div>
1266
+ </noscript><div style="display:none" id="prettify-lang">lang-rb</div></div>
1267
+
1268
+ <script>
1269
+ $('#wmd-input').one("keypress", function() {
1270
+ $.ajax({
1271
+ url: '/accounts/email-settings-form',
1272
+ cache: false,
1273
+ success: function(data) {
1274
+ $('#submit-button').parent().prepend(data);
1275
+ }
1276
+ });
1277
+ });
1278
+
1279
+ </script>
1280
+
1281
+
1282
+ </div>
1283
+ </div>
1284
+ <div id="footer" class="categories">
1285
+ <div class="footerwrap">
1286
+ <div id="footer-menu">
1287
+ <div class="top-footer-links">
1288
+ <a href="/tour">tour</a>
1289
+ <a href="/help">help</a>
1290
+ <a href="http://blog.stackoverflow.com?blb=1">blog</a>
1291
+ <a href="http://chat.stackoverflow.com">chat</a>
1292
+ <a href="http://data.stackexchange.com">data</a>
1293
+ <a href="http://stackexchange.com/legal">legal</a>
1294
+ <a href="http://stackexchange.com/legal/privacy-policy">privacy policy</a>
1295
+ <a href="http://stackexchange.com/work-here">work here</a>
1296
+ <a href="http://stackexchange.com/mediakit">advertising info</a>
1297
+
1298
+ <a onclick='StackExchange.switchMobile("on")'>mobile</a>
1299
+ <b><a href="/contact">contact us</a></b>
1300
+ <b><a href="http://meta.stackoverflow.com">feedback</a></b>
1301
+
1302
+ </div>
1303
+ <div id="footer-sites">
1304
+ <table>
1305
+ <tr>
1306
+ <th colspan=3>
1307
+ Technology
1308
+ </th>
1309
+ <th >
1310
+ Life / Arts
1311
+ </th>
1312
+ <th >
1313
+ Culture / Recreation
1314
+ </th>
1315
+ <th >
1316
+ Science
1317
+ </th>
1318
+ <th >
1319
+ Other
1320
+ </th>
1321
+ </tr>
1322
+ <tr>
1323
+ <td>
1324
+ <ol>
1325
+ <li><a href="//stackoverflow.com" title="professional and enthusiast programmers">Stack Overflow</a></li>
1326
+ <li><a href="//serverfault.com" title="system and network administrators">Server Fault</a></li>
1327
+ <li><a href="//superuser.com" title="computer enthusiasts and power users">Super User</a></li>
1328
+ <li><a href="//webapps.stackexchange.com" title="power users of web applications">Web Applications</a></li>
1329
+ <li><a href="//askubuntu.com" title="Ubuntu users and developers">Ask Ubuntu</a></li>
1330
+ <li><a href="//webmasters.stackexchange.com" title="pro webmasters">Webmasters</a></li>
1331
+ <li><a href="//gamedev.stackexchange.com" title="professional and independent game developers">Game Development</a></li>
1332
+ <li><a href="//tex.stackexchange.com" title="users of TeX, LaTeX, ConTeXt, and related typesetting systems">TeX - LaTeX</a></li>
1333
+ </ol></td><td><ol>
1334
+ <li><a href="//programmers.stackexchange.com" title="professional programmers interested in conceptual questions about software development">Programmers</a></li>
1335
+ <li><a href="//unix.stackexchange.com" title="users of Linux, FreeBSD and other Un*x-like operating systems.">Unix &amp; Linux</a></li>
1336
+ <li><a href="//apple.stackexchange.com" title="power users of Apple hardware and software">Ask Different (Apple)</a></li>
1337
+ <li><a href="//wordpress.stackexchange.com" title="WordPress developers and administrators">WordPress Development</a></li>
1338
+ <li><a href="//gis.stackexchange.com" title="cartographers, geographers and GIS professionals">Geographic Information Systems</a></li>
1339
+ <li><a href="//electronics.stackexchange.com" title="electronics and electrical engineering professionals, students, and enthusiasts">Electrical Engineering</a></li>
1340
+ <li><a href="//android.stackexchange.com" title="enthusiasts and power users of the Android operating system">Android Enthusiasts</a></li>
1341
+ <li><a href="//security.stackexchange.com" title="Information security professionals">Information Security</a></li>
1342
+ </ol></td><td><ol>
1343
+ <li><a href="//dba.stackexchange.com" title="database professionals who wish to improve their database skills and learn from others in the community">Database Administrators</a></li>
1344
+ <li><a href="//drupal.stackexchange.com" title="Drupal developers and administrators">Drupal Answers</a></li>
1345
+ <li><a href="//sharepoint.stackexchange.com" title="SharePoint enthusiasts">SharePoint</a></li>
1346
+ <li><a href="//ux.stackexchange.com" title="user experience researchers and experts">User Experience</a></li>
1347
+ <li><a href="//mathematica.stackexchange.com" title="users of Mathematica">Mathematica</a></li>
1348
+ <li><a href="//salesforce.stackexchange.com" title="Salesforce administrators, implementation experts, developers and anybody in-between">Salesforce</a></li>
1349
+
1350
+ <li>
1351
+ <a href="http://stackexchange.com/sites#technology" class="more">
1352
+ more (14)
1353
+ </a>
1354
+ </li>
1355
+ </ol>
1356
+ </td>
1357
+ <td>
1358
+ <ol>
1359
+ <li><a href="//photo.stackexchange.com" title="professional, enthusiast and amateur photographers">Photography</a></li>
1360
+ <li><a href="//scifi.stackexchange.com" title="science fiction and fantasy enthusiasts">Science Fiction &amp; Fantasy</a></li>
1361
+ <li><a href="//graphicdesign.stackexchange.com" title="Graphic Design professionals, students, and enthusiasts">Graphic Design</a></li>
1362
+ <li><a href="//cooking.stackexchange.com" title="professional and amateur chefs">Seasoned Advice (cooking)</a></li>
1363
+ <li><a href="//diy.stackexchange.com" title="contractors and serious DIYers">Home Improvement</a></li>
1364
+ <li><a href="//money.stackexchange.com" title="people who want to be financially literate">Personal Finance &amp; Money</a></li>
1365
+ <li><a href="//academia.stackexchange.com" title="academics and those enrolled in higher education">Academia</a></li>
1366
+
1367
+ <li>
1368
+ <a href="http://stackexchange.com/sites#lifearts" class="more">
1369
+ more (10)
1370
+ </a>
1371
+ </li>
1372
+ </ol>
1373
+ </td>
1374
+ <td>
1375
+ <ol>
1376
+ <li><a href="//english.stackexchange.com" title="linguists, etymologists, and serious English language enthusiasts">English Language &amp; Usage</a></li>
1377
+ <li><a href="//skeptics.stackexchange.com" title="scientific skepticism">Skeptics</a></li>
1378
+ <li><a href="//judaism.stackexchange.com" title="those who base their lives on Jewish law and tradition and anyone interested in learning more">Mi Yodeya (Judaism)</a></li>
1379
+ <li><a href="//travel.stackexchange.com" title="road warriors and seasoned travelers">Travel</a></li>
1380
+ <li><a href="//christianity.stackexchange.com" title="committed Christians, experts in Christianity and those interested in learning more">Christianity</a></li>
1381
+ <li><a href="//gaming.stackexchange.com" title="passionate videogamers on all platforms">Arqade (gaming)</a></li>
1382
+ <li><a href="//bicycles.stackexchange.com" title="people who build and repair bicycles, people who train cycling, or commute on bicycles">Bicycles</a></li>
1383
+ <li><a href="//rpg.stackexchange.com" title="gamemasters and players of tabletop, paper-and-pencil role-playing games">Role-playing Games</a></li>
1384
+
1385
+ <li>
1386
+ <a href="http://stackexchange.com/sites#culturerecreation" class="more">
1387
+ more (21)
1388
+ </a>
1389
+ </li>
1390
+ </ol>
1391
+ </td>
1392
+ <td>
1393
+ <ol>
1394
+ <li><a href="//math.stackexchange.com" title="people studying math at any level and professionals in related fields">Mathematics</a></li>
1395
+ <li><a href="//stats.stackexchange.com" title="people interested in statistics, machine learning, data analysis, data mining, and data visualization">Cross Validated (stats)</a></li>
1396
+ <li><a href="//cstheory.stackexchange.com" title="theoretical computer scientists and researchers in related fields">Theoretical Computer Science</a></li>
1397
+ <li><a href="//physics.stackexchange.com" title="active researchers, academics and students of physics">Physics</a></li>
1398
+ <li><a href="//mathoverflow.net" title="professional mathematicians">MathOverflow</a></li>
1399
+
1400
+ <li>
1401
+ <a href="http://stackexchange.com/sites#science" class="more">
1402
+ more (7)
1403
+ </a>
1404
+ </li>
1405
+ </ol>
1406
+ </td>
1407
+ <td>
1408
+ <ol>
1409
+ <li><a href="//stackapps.com" title="apps, scripts, and development with the Stack Exchange API">Stack Apps</a></li>
1410
+ <li><a href="//meta.stackexchange.com" title="meta-discussion of the Stack Exchange family of Q&amp;A websites">Meta Stack Exchange</a></li>
1411
+ <li><a href="//area51.stackexchange.com" title="proposing new sites in the Stack Exchange network">Area 51</a></li>
1412
+ <li><a href="//careers.stackoverflow.com">Stack Overflow Careers</a></li>
1413
+
1414
+ </ol>
1415
+ </td>
1416
+ </tr>
1417
+ </table>
1418
+ </div>
1419
+ </div>
1420
+
1421
+ <div id="copyright">
1422
+ site design / logo &#169; 2015 stack exchange inc; user contributions licensed under <a href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license">cc by-sa 3.0</a>
1423
+ with <a href="http://blog.stackoverflow.com/2009/06/attribution-required/" rel="license">attribution required</a>
1424
+ </div>
1425
+ <div id="svnrev">
1426
+ rev 2015.3.9.2373
1427
+ </div>
1428
+
1429
+ </div>
1430
+ </div>
1431
+ <noscript>
1432
+ <div id="noscript-warning">Stack Overflow works best with JavaScript enabled<img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno"></div>
1433
+ </noscript>
1434
+ <script>var p = "http", d = "static"; if (document.location.protocol == "https:") { p += "s"; d = "engine"; } var z = document.createElement("script"); z.type = "text/javascript"; z.async = true; z.src = p + "://" + d + ".adzerk.net/ados.js"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(z, s);</script>
1435
+ <script>
1436
+ var ados = ados || {};
1437
+ ados.run = ados.run || [];
1438
+ ados.run.push(function () { ados_setKeywords('ruby,arrays,each,x-user-registered,x-1500plus-rep');; ados_load(); });
1439
+ </script>
1440
+
1441
+ <script>
1442
+ (function (i, s, o, g, r, a, m) {
1443
+ i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () { (i[r].q = i[r].q || []).push(arguments) }, i[r].l = 1 * new Date(); a = s.createElement(o),
1444
+ m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m);
1445
+ })(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
1446
+ ga('create', 'UA-5620270-1');
1447
+ ga('set', 'dimension1', '1529114');
1448
+ ga('set', 'dimension2', '|ruby|arrays|each|');
1449
+ ga('send', 'pageview');
1450
+ var _qevents = _qevents || [],
1451
+ _comscore = _comscore || [];
1452
+ (function () {
1453
+ var ssl='https:'==document.location.protocol,
1454
+ s=document.getElementsByTagName('script')[0],
1455
+ qc=document.createElement('script');
1456
+ qc.async=true;
1457
+ qc.src=(ssl?'https://secure':'http://edge')+'.quantserve.com/quant.js';
1458
+ s.parentNode.insertBefore(qc, s);
1459
+ var sc=document.createElement('script');
1460
+ sc.async=true;
1461
+ sc.src=(ssl?'https://sb':'http://b') + '.scorecardresearch.com/beacon.js';
1462
+ s.parentNode.insertBefore(sc, s);
1463
+ })();
1464
+ _comscore.push({ c1: "2", c2: "17440561" });
1465
+ _qevents.push({ qacct: "p-c1rF4kxgLUzNc" });
1466
+ </script>
1467
+
1468
+ </body>
1469
+ </html>