Class: Object

Inherits:
BasicObject
Defined in:
lib/eac_ruby_utils/patches/object/asserts.rb,
lib/eac_ruby_utils/patches/object/if_present.rb

Instance Method Summary collapse

Instance Method Details

#assert_argument(klass, argument_name = 'unknown_argument_name') ⇒ Object

Raises a ArgumentError if self is not a klass.

Returns:

  • self

Raises:

  • (::ArgumentError)


7
8
9
10
11
12
# File 'lib/eac_ruby_utils/patches/object/asserts.rb', line 7

def assert_argument(klass, argument_name = 'unknown_argument_name')
  return self if is_a?(klass)
  raise ::ArgumentError,
        "Argument \"#{argument_name}\" is not a #{klass}" \
        "(Actual class: #{self.class}, actual value: #{self})"
end

#if_present(default_value = nil) ⇒ Object



7
8
9
10
# File 'lib/eac_ruby_utils/patches/object/if_present.rb', line 7

def if_present(default_value = nil)
  return default_value unless present?
  block_given? ? yield(self) : self
end