Class: Lookout::Stub::Method

Inherits:
Object
  • Object
show all
Defined in:
lib/lookout/stub/method.rb

Direct Known Subclasses

Mock::Method

Defined Under Namespace

Classes: Each, Values

Instance Method Summary collapse

Constructor Details

#initialize(object, method, &body) ⇒ Method

Returns a new instance of Method.



32
33
34
35
36
# File 'lib/lookout/stub/method.rb', line 32

def initialize(object, method, &body)
  @object, @method, @body = object, method.to_sym, body || Nil
  @yield = nil
  @defined = false
end

Instance Method Details

#call(*args, &block) ⇒ Object



55
56
57
58
# File 'lib/lookout/stub/method.rb', line 55

def call(*args, &block)
  @yield.call(&block) if @yield and block
  @body.call(*args)
end

#defineObject



48
49
50
51
52
53
# File 'lib/lookout/stub/method.rb', line 48

def define
  return self if @defined
  define!
  @defined = true
  self
end

#each(*values) ⇒ Object



43
44
45
46
# File 'lib/lookout/stub/method.rb', line 43

def each(*values)
  @yield = Each.new(*values)
  self
end

#undefineObject



60
61
62
63
64
65
# File 'lib/lookout/stub/method.rb', line 60

def undefine
  return self unless @defined
  undefine!
  @defined = false
  self
end

#yield(*values) ⇒ Object



38
39
40
41
# File 'lib/lookout/stub/method.rb', line 38

def yield(*values)
  @yield = Values.new(*values)
  self
end