Module: Polyfill::V2_6::Kernel

Defined in:
lib/polyfill/v2_6/kernel.rb

Instance Method Summary collapse

Instance Method Details

#Complex(*args, exception: true) ⇒ Object

rubocop:disable Naming/MethodName



6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/polyfill/v2_6/kernel.rb', line 6

def Complex(*args, exception: true) # rubocop:disable Naming/MethodName
  super(*args) if exception

  x, y = *args
  if !x.nil? && !x.is_a?(::String) && !x.is_a?(::Numeric) && !y.nil? && y.is_a?(::Numeric)
    raise ::TypeError, 'not a real'
  end

  begin
    super(*args)
  rescue ::ArgumentError, ::TypeError
    nil
  end
end

#Float(arg, exception: true) ⇒ Object

rubocop:disable Naming/MethodName



21
22
23
24
25
26
27
28
29
# File 'lib/polyfill/v2_6/kernel.rb', line 21

def Float(arg, exception: true) # rubocop:disable Naming/MethodName
  super(arg) if exception

  begin
    super(arg)
  rescue ::ArgumentError, ::TypeError
    nil
  end
end

#Integer(arg, exception: true) ⇒ Object

rubocop:disable Naming/MethodName



31
32
33
34
35
36
37
38
39
# File 'lib/polyfill/v2_6/kernel.rb', line 31

def Integer(arg, exception: true) # rubocop:disable Naming/MethodName
  super(arg) if exception

  begin
    super(arg)
  rescue ::ArgumentError, ::TypeError, ::FloatDomainError
    nil
  end
end

#Rational(*args, exception: true) ⇒ Object

rubocop:disable Naming/MethodName



41
42
43
44
45
46
47
48
49
# File 'lib/polyfill/v2_6/kernel.rb', line 41

def Rational(*args, exception: true) # rubocop:disable Naming/MethodName
  super(*args) if exception

  begin
    super(*args)
  rescue ::ArgumentError, ::TypeError
    nil
  end
end

#thenObject



51
52
53
54
55
# File 'lib/polyfill/v2_6/kernel.rb', line 51

def then
  return yield_self unless block_given?

  yield_self(&::Proc.new)
end