Top Level Namespace

Defined Under Namespace

Modules: Gosling, ObjectCache, Snow Classes: MatrixCache, Object, VectorCache

Instance Method Summary collapse

Instance Method Details

#boolean_check(obj) ⇒ Object

Raises an ArgumentError unless the object is truthy.

Raises:

  • (ArgumentError)


18
19
20
# File 'lib/gosling/utils.rb', line 18

def boolean_check(obj)
  raise ArgumentError.new("Expected true or false, but received #{obj.inspect}!") unless [true, false].include?(obj)
end

#type_check(obj, type) ⇒ Object

Raises an ArgumentError unless the object is of the specified type.

Raises:

  • (ArgumentError)


4
5
6
# File 'lib/gosling/utils.rb', line 4

def type_check(obj, type)
  raise ArgumentError.new("Expected #{type}, but received #{obj.inspect}!") unless obj.is_a?(type)
end

#types_check(obj, *types) ⇒ Object

Raises an ArgumentError unless the object is one of the listed types.

Raises:

  • (ArgumentError)


11
12
13
# File 'lib/gosling/utils.rb', line 11

def types_check(obj, *types)
  raise ArgumentError.new("Expected one of #{types.inspect}, but received #{obj.inspect}!") unless types.any? { |type| obj.is_a?(type) }
end