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
# File 'lib/arbitrary_mock/base.rb', line 8

def method_missing(*args)
  method_name = args.first
  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[1]
end