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)

Instance Method Details

- (Object) metaclass

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 metaclass
  class << self; self end
end

- (Object) tap {|_self| ... }

Yields:

  • (_self)

Yield Parameters:

  • _self (Object)

    the object that the method was called on



17
18
19
20
# File 'lib/babushka/core_patches/object.rb', line 17

def tap &block
  yield self
  self
end

- (Object) tapp

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 { STDOUT.puts "#{File.basename caller[2]}: #{self.inspect}" }
end