Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/eac_ruby_utils/patches/object/debug.rb,
lib/eac_ruby_utils/patches/object/if_nil.rb,
lib/eac_ruby_utils/patches/object/asserts.rb,
lib/eac_ruby_utils/patches/object/compact.rb,
lib/eac_ruby_utils/patches/object/if_present.rb,
lib/eac_ruby_utils/patches/object/if_respond.rb,
lib/eac_ruby_utils/patches/object/to_pathname.rb
Instance Method Summary collapse
-
#assert_argument(klass, argument_name = 'unknown_argument_name') ⇒ Object
Raises a ArgumentError if
self
is not aklass
. - #compact(*attributes) ⇒ EacRubyUtils::Compact
- #compact_to_a(*attributes) ⇒ Array
- #compact_to_h(*attributes) ⇒ Hash
-
#if_blank ⇒ Object
yield
ifself
is blank. -
#if_nil ⇒ Object
yield
ifself
is nil,self
otherwise. - #if_not_nil(default_value = nil) ⇒ Object
- #if_present(default_value = nil) ⇒ Object
-
#if_respond(method_name, default_value = nil) ⇒ Object
otherwise.
- #print_debug ⇒ Object
- #raise_debug ⇒ Object
- #to_debug ⇒ Object
-
#to_pathname ⇒ Pathname
Convert
self
to String and then to Pathname.
Instance Method Details
#assert_argument(klass, argument_name = 'unknown_argument_name') ⇒ Object
Raises a ArgumentError if self
is not a klass
.
7 8 9 10 11 12 13 |
# 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 |
#compact(*attributes) ⇒ EacRubyUtils::Compact
7 8 9 |
# File 'lib/eac_ruby_utils/patches/object/compact.rb', line 7 def compact(*attributes) ::EacRubyUtils::Compact.new(self, attributes) end |
#compact_to_a(*attributes) ⇒ Array
12 13 14 |
# File 'lib/eac_ruby_utils/patches/object/compact.rb', line 12 def compact_to_a(*attributes) compact(*attributes).to_a end |
#compact_to_h(*attributes) ⇒ Hash
17 18 19 |
# File 'lib/eac_ruby_utils/patches/object/compact.rb', line 17 def compact_to_h(*attributes) compact(*attributes).to_h end |
#if_blank ⇒ Object
Returns yield
if self
is blank.
14 15 16 17 18 |
# 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 ⇒ Object
Returns yield
if self
is nil, self
otherwise.
12 13 14 15 16 |
# 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) ⇒ Object
5 6 7 8 9 |
# 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) ⇒ Object
7 8 9 10 11 |
# 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) ⇒ Object
otherwise.
8 9 10 11 12 13 14 |
# 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 ⇒ Object
4 5 6 7 8 |
# File 'lib/eac_ruby_utils/patches/object/debug.rb', line 4 def print_debug STDERR.write(to_debug + "\n") self end |
#raise_debug ⇒ Object
14 15 16 |
# File 'lib/eac_ruby_utils/patches/object/debug.rb', line 14 def raise_debug raise to_debug end |
#to_debug ⇒ Object
10 11 12 |
# File 'lib/eac_ruby_utils/patches/object/debug.rb', line 10 def to_debug "|#{self.class}|#{self}|" end |