Method: Wgit::Assertable#assert_types
- Defined in:
- lib/wgit/assertable.rb
#assert_types(obj, type_or_types, msg = nil) ⇒ Object Also known as: assert_type
Tests if the obj is_a? given type; raises an Exception if not.
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/wgit/assertable.rb', line 31 def assert_types(obj, type_or_types, msg = nil) msg ||= format(DEFAULT_TYPE_FAIL_MSG, type_or_types, obj.class) match = if type_or_types.respond_to?(:any?) type_or_types.any? { |type| obj.is_a?(type) } else obj.is_a?(type_or_types) end raise msg unless match obj end |