Question: I'm currently experimenting with moving functionality into engines. It works nicely so far, but I'm a bit confused why certain parts of the engine are always automatically reloaded when something changed, and some are not.

Specifically, when adding a helper method, I have to restart the Rails server, otherwise it is not seen by Rails. Is this normal behavior? Here's the relevant part of my engine:

components/iq\_list.rb

```
# encoding: utf-8
require 'iq_list/engine'

# Load IqList Modules
module IqList
  extend ActiveSupport::Autoload
  autoload :Helpers
  autoload :Models
  autoload :Controllers
end

```

components/iq\_list/engine.rb

```
module IqList
  class Engine < ::Rails::Engine
  end
end

```

components/iq\_list/helpers.rb

```
module IqList
  module Helpers
    extend ActiveSupport::Autoload
    autoload :IqListHelper
  end
end

```

components/iq\_list/helpers/iq\_list\_helper.rb

```
module IqList
  module Helpers
    module IqListHelper
      def some_method
        # ...
      end
    end
  end
end

```

I'm still very new to engines, and a lot of the code above I have taken from somebody else's work, so please be patient with me. Any hint into the right direction is highly appreciated.

Answer: 
My code is an example of using the recursive function walk(). I hope it would help you solve the problem.

```
input = ['01100011100100000',
         '11100011111111011',
         '10011111101011011']
col_len = 17
row_len = 3

walked = []
output = []

def walk(subset_in, row, col):
    if (0 <= row < row_len) and (0 <= col < col_len) and (row, col) not in walked:
        walked.append((row, col))
        if input[row][col] == '0':
            if subset_in is not None:
                subset = subset_in
            else:
                subset = []

            subset.append((row, col))
            walk(subset, row, col+1)
            walk(subset, row+1, col)
            walk(subset, row, col-1)
            walk(subset, row-1, col)

            if subset_in is None:
                output.append(subset)

for row in xrange(row_len):
    for col in xrange(col_len):
        if (row, col) not in walked:
            walk(None, row, col)

for subset in output: print subset

```
to break out of recursion you need to use return. If your recursion continues furthermore, you need to re consider your base case.

just for fun I tried using networkx for this, not that it answers your question:

```
data = """01100011100100000
11100011111111011
10011111101011011""".splitlines()

import networkx

G = networkx.Graph()
found = set()

for i, row in enumerate(data):
    for j, c in enumerate(row):
        if c == '0':
            found.add((i, j))
            if i + 1 < len(data) and data[i + 1][j] == '0':
                G.add_edge((i, j), (i + 1, j))
            if j + 1 < len(row) and row[j + 1] == '0':
                G.add_edge((i, j), (i, j + 1))

groups = map(list, networkx.connected_component_subgraphs(G))
group_nodes = set(node for group in groups for node in group)
individuals = found - group_nodes

print groups
print individuals

"""
[[(0, 15), (0, 14), (1, 14), (0, 13), (0, 12), (0, 16), (2, 14)], [(1, 3), (1, 4), (1, 5), (0, 5), (0, 4), (0, 3)], [(2, 1), (2, 2)], [(0, 9), (0, 10)]]
set([(0, 0), (2, 11), (2, 9)])
"""

```