Module: ConcatHeredocHorizontal

Defined in:
lib/concat_heredoc_horizontal.rb,
lib/concat_heredoc_horizontal/version.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.concat_simple(str_1, str_2) ⇒ Object

Your code goes here...



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/concat_heredoc_horizontal.rb', line 8

def self.concat_simple(str_1, str_2)
  i = 0
  j = 0
  k = 0
  lim_sup = (str_1.count("\n") > str_2.count("\n"))? str_1.count("\n") : str_2.count("\n")
  str = ""
  str_result = str.dup

  while i <= lim_sup
    while j < str_1.length
      unless str_1[j].eql?("\n")
        str_result << str_1[j]
      else
        j += 1
        break
      end
      j += 1
    end

    while k < str_2.length
      unless str_2[k].eql?("\n")
        str_result << str_2[k]
      else
        k += 1
        break
      end
      k += 1
    end

    str_result << "\n"
    i += 1
  end

  return str_result.chomp
end