Class: ArbitraryMock::Base
- Inherits:
-
Object
- Object
- ArbitraryMock::Base
- Defined in:
- lib/arbitrary_mock/base.rb
Instance Method Summary collapse
-
#initialize(property_hash = {}) ⇒ Base
constructor
A new instance of Base.
- #method_missing(*args) ⇒ Object
- #try(*args) ⇒ Object
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 |