File: introduce11.rb.testApplyExtractMethodConditionals1.fixed

package info (click to toggle)
netbeans-ide 6.0.1%2Bdfsg-2
  • links: PTS, VCS
  • area: contrib
  • in suites: lenny
  • size: 741,536 kB
  • ctags: 613,961
  • sloc: java: 3,969,489; xml: 336,553; jsp: 11,861; ruby: 10,091; cpp: 4,127; sh: 3,417; ansic: 1,734; sql: 1,306; haskell: 1,019; makefile: 487; perl: 403; objc: 288; php: 120
file content (59 lines) | stat: -rw-r--r-- 1,245 bytes parent folder | download
1
2
3
4
5
6
7
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class ExtractMethodSample
  def stress_test0(a)
    c = 1
    
    # begin
    if (a < 5)
      puts c
    end
    c = 2
    c += a
    # end
    
    puts a,c
  end

  def stress_test1(a,b)
    c = 1, d = 2, e = 3

    # Begin
    a, c, g, i = extract(a, b, d)
    # End

    puts g
    if (a < 5)
      i = 55
    end
    h = 5
    puts h, e, c, i
  end
  
  # TODO Comment
  def extract(a, b, d)
    if (b > 4)
      a = 1
    end
    c = a
    f = d+2
    g = b+3
    h = g
    i = 5
    c += h
    return a, c, g, i
  end 
end

# Notice:
# a, b and d are accessed from within the fragment, so they are passed in.
# c is reassigned in the fragment without reading the previous value, so
#   doesn't need to be passed in.
# f and h are assigned locally inside the extracted fragment, but are not read
#   outside of it, so does not need to be passed back out
# g is assigned inside the fragment, and read later outside, so it is returned
#   from the new method but not passed in
# h is assigned inside the fragment, and is read later, but it is assigned
#   before this read access so the value doesn't need to be passed back
# i is also assigned inside the fragment, and -may- be read after the fragment,
#   so it too is passed back out