File: kernel.rb

package info (click to toggle)
ruby-backports 3.25.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,912 kB
  • sloc: ruby: 11,757; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 554 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# frozen_string_literal: true

require 'backports/tools/deprecation'

Backports.deprecate :rails, 'Rails backports are deprecated.'

# From ActiveSupport
unless Object.method_defined? :try
  class Object
    def try(*a, &b)
      if a.empty? || respond_to?(a.first)
        if a.empty? && block_given?
          if b.arity == 0
            instance_eval(&b)
          else
            yield self
          end
        else
          public_send(*a, &b)
        end
      end
    end
  end

  class NilClass
    def try(*args)
      nil
    end
  end
end