class Object

Public Instance Methods

assert_argument(klass, argument_name = 'unknown_argument_name') click to toggle source

Raises a ArgumentError if self is not a klass.

@return self

# 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_blank() { || ... } click to toggle source

@return yield if self is blank.

# File lib/eac_ruby_utils/patches/object/if_present.rb, line 14
def if_blank
  return yield if blank? && block_given?

  self
end
if_nil() { || ... } click to toggle source

@return yield if self is nil, self otherwise.

# File lib/eac_ruby_utils/patches/object/if_nil.rb, line 12
def if_nil
  return yield if nil? && block_given?

  self
end
if_not_nil(default_value = nil) { |self| ... } click to toggle source

@return +block.call(self)+ if self is not nil, default_value otherwise.

# File lib/eac_ruby_utils/patches/object/if_nil.rb, line 5
def if_not_nil(default_value = nil)
  return default_value if nil?

  block_given? ? yield(self) : self
end
if_present(default_value = nil) { |self| ... } click to toggle source

@return +block.call(self)+ if self is present, default_value otherwise.

# File lib/eac_ruby_utils/patches/object/if_present.rb, line 7
def if_present(default_value = nil)
  return default_value if blank?

  block_given? ? yield(self) : self
end
if_respond(method_name, default_value = nil) { |value| ... } click to toggle source

@return +block.call(self.method_name)+ if self responds to method_name, default_value otherwise.

# File lib/eac_ruby_utils/patches/object/if_respond.rb, line 8
def if_respond(method_name, default_value = nil)
  return default_value unless respond_to?(method_name)

  value = send(method_name)

  block_given? ? yield(value) : value
end
print_debug() click to toggle source
raise_debug() click to toggle source
# File lib/eac_ruby_utils/patches/object/debug.rb, line 14
def raise_debug
  raise to_debug
end
to_debug() click to toggle source
# File lib/eac_ruby_utils/patches/object/debug.rb, line 10
def to_debug
  "|#{self.class}|#{self}|"
end
to_pathname() click to toggle source

Convert self to String and then to Pathname. Return nil if self is blank?.

@return [Pathname]

# File lib/eac_ruby_utils/patches/object/to_pathname.rb, line 10
def to_pathname
  return self if is_a?(::Pathname)

  to_s.blank? ? nil : ::Pathname.new(to_s)
end