Module: Stub::Abstract::Methods

Defined in:
lib/stub/abstract.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/stub/abstract.rb', line 22

def method_missing method_name, *args, &block
	result = @object.send method_name, *args, &block

	method_name = args.shift if [ :send, :__send__ ].include? method_name

	case result
	when nil
		raise
	when true, false, String, Numeric, Array, Hash
		result
	else
		__wrap__ result, method_name, *args, &block
	end
rescue => e
	$stderr.puts "#{e.class}: #{e.message} in #{@object.class}##{method_name}(#{args.map(&:inspect)*','})" if e.message.present?

	__stub__ method_name, *args, &block
end

Instance Method Details

#__wrap__(object, *context) ⇒ Object



41
42
43
# File 'lib/stub/abstract.rb', line 41

def __wrap__ object, *context
	@stub_class.new object
end