Class: Tattletail::Fib

Inherits:
Object show all
Defined in:
lib/tattletail/demo.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fib(x) ⇒ Object



16
17
18
19
# File 'lib/tattletail/demo.rb', line 16

def self.fib x
  return 1 if x <= 2
  fib(x - 1) + fib(x - 2)
end

.find(x) ⇒ Object



22
23
24
25
# File 'lib/tattletail/demo.rb', line 22

def self.find x
  return 1 if x <= 2
  find(x - 1) + find(x - 2)
end

Instance Method Details

#fib(x) ⇒ Object



10
11
12
13
# File 'lib/tattletail/demo.rb', line 10

def fib x
  return 1 if x <= 2
  fib(x - 1) + fib(x - 2)
end

#fib_block(&blk) ⇒ Object



33
34
35
# File 'lib/tattletail/demo.rb', line 33

def fib_block &blk
  fib yield
end

#fib_missing(n) ⇒ Object



43
44
45
# File 'lib/tattletail/demo.rb', line 43

def fib_missing n
  foo n
end

#fib_raise(n) ⇒ Object



38
39
40
# File 'lib/tattletail/demo.rb', line 38

def fib_raise n
  raise 'This method always raises a generic exception'
end

#find(x) ⇒ Object



28
29
30
# File 'lib/tattletail/demo.rb', line 28

def find x
  x * 2
end

#no_argsObject



5
6
7
# File 'lib/tattletail/demo.rb', line 5

def no_args
  5
end

#raise_testObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tattletail/demo.rb', line 48

def raise_test
  5.times do |n|
    if n % 2 == 0
      fib n
    else
      begin
        if n % 4 == 1
          fib_raise n
        else
          fib_missing n
        end
      rescue Exception => e
        e
      end
      n
    end
  end
end