Class: Object
- Inherits:
- BasicObject
- Defined in:
- lib/babushka/core_patches/try.rb,
lib/babushka/core_patches/object.rb
Overview
The implementation of #try as found in activesupport:
lib/active_support/core_ext/object/try.rb
Try is just a nil-swallowing send, which means return nil when called on nil and just send like normal when called on any other object.
Instance Method Summary collapse
-
#metaclass ⇒ Object
Return this object’s metaclass; i.e.
-
#tap {|_self| ... } ⇒ Object
Return this object after yielding it to the block.
-
#tapp ⇒ Object
Return self unmodified after logging the output of #inspect, along with the point at which
tapp
was called.
Instance Method Details
#metaclass ⇒ Object
Return this object’s metaclass; i.e. the value of self within a ‘class << self’ block.
6 7 8 |
# File 'lib/babushka/core_patches/object.rb', line 6 def class << self; self end end |
#tap {|_self| ... } ⇒ Object
Return this object after yielding it to the block. This is useful for neatly working with an object in some way before returning it:
def valmorphanize
process.tap {|result|
log_error "Oops!" unless result
}
end
17 18 19 20 |
# File 'lib/babushka/core_patches/object.rb', line 17 def tap &block yield self self end |
#tapp ⇒ Object
Return self unmodified after logging the output of #inspect, along with the point at which tapp
was called.
24 25 26 |
# File 'lib/babushka/core_patches/object.rb', line 24 def tapp tap { puts "#{File.basename caller[2]}: #{self.inspect}" } end |