elasticsearch-ruby

https://github.com/elastic/elasticsearch-ruby

Ruby

Ruby integrations for Elasticsearch

Opal::Rewriters::ForRewriter#on_for

Handles
  for i in 0..3; j = i + 1; end

The problem here is that in Ruby for loop makes its
loop variable + all local variables available outside.
I.e. after this loop variable `i` is 3 and `j` is 4

This class rewrites it to the following code:
  j = nil
  i = nil
  (0..3).each { |__jstmp| i = __jstmp; j = i + 1 }

Complex stuff with multiple loop variables:
  for i, j in [[1, 2], [3, 4]]; end
Becomes multiple left-hand assignment:
  i = nil
  j = nil
  [[1, 2], [3, 4]].each { |__jstmp| i, j = __jstmp }

Source | Google | Stack overflow

Edit

git clone [email protected]:elastic/elasticsearch-ruby.git

cd elasticsearch-ruby

open

Contribute

# Make a new branch

git checkout -b -your-name--update-docs-Opal--Rewriters--ForRewriter-on_for-for-pr


# Commit to git

git add git commit -m "better docs for Opal::Rewriters::ForRewriter#on_for"


# Open pull request

gem install hub # on a mac you can `brew install hub`

hub fork

git push <your name> -your-name--update-docs-Opal--Rewriters--ForRewriter-on_for-for-pr

hub pull-request


# Celebrate!