Sha256: fd45b1d8607fccbc4bebc9a7607f2bcd9e36a0e0f044b755ed7c6db6b915e390

Contents?: true

Size: 451 Bytes

Versions: 4

Compression:

Stored size: 451 Bytes

Contents

# frozen_string_literal: true

module AppInfo
  # Monkey Patch for Object
  module Tryable
    def try(*a, &b)
      try!(*a, &b) if a.empty? || respond_to?(a.first)
    end

    def try!(*a, &b)
      if a.empty? && block_given?
        if b.arity.zero?
          instance_eval(&b)
        else
          yield self
        end
      else
        public_send(*a, &b)
      end
    end
  end
end

# :nodoc:
class Object
  include AppInfo::Tryable
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
app-info-2.0.0 lib/app_info/core_ext/object/try.rb
app-info-2.0.0.rc1 lib/app_info/core_ext/object/try.rb
app-info-2.0.0.beta7 lib/app_info/core_ext/object/try.rb
app-info-2.0.0.beta4 lib/app_info/core_ext/object/try.rb