Class: ArbitraryMock::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/arbitrary_mock/base.rb

Instance Method Summary collapse

Constructor Details

#initialize(property_hash = {}) ⇒ Base

Returns a new instance of Base.



4
5
6
# File 'lib/arbitrary_mock/base.rb', line 4

def initialize(property_hash={})
  @property_hash = property_hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/arbitrary_mock/base.rb', line 8

def method_missing(*args)
  method_name = args.first
  arg_position = 1

  if method_name == :try
    method_name = args[1]
    arg_position += 1
  end

  setter_method_match = /(.*)=$/.match(method_name)

  return @property_hash[method_name] if setter_method_match.nil?

  setter_method = setter_method_match.captures.first.to_sym
  @property_hash[setter_method] = args[arg_position]
end

Instance Method Details

#try(*args) ⇒ Object



25
26
27
# File 'lib/arbitrary_mock/base.rb', line 25

def try(*args)
  self.send *args
end