hanami-utils 2.0.0.alpha6 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Hanami
4
- module Utils
5
- # BasicObject
6
- #
7
- # @since 0.3.5
8
- class BasicObject < ::BasicObject
9
- # Lookups constants at the top-level namespace, if they are missing in the
10
- # current context.
11
- #
12
- # @param name [Symbol] the constant name
13
- #
14
- # @return [Object, Module] the constant
15
- #
16
- # @raise [NameError] if the constant cannot be found
17
- #
18
- # @since 1.3.4
19
- # @api private
20
- #
21
- # @see https://ruby-doc.org/core/Module.html#method-i-const_missing
22
- def self.const_missing(name)
23
- ::Object.const_get(name)
24
- end
25
-
26
- # Returns the class for debugging purposes.
27
- #
28
- # @since 0.3.5
29
- #
30
- # @see http://ruby-doc.org/core/Object.html#method-i-class
31
- def class
32
- (class << self; self; end).superclass
33
- end
34
-
35
- # Bare minimum inspect for debugging purposes.
36
- #
37
- # @return [String] the inspect string
38
- #
39
- # @since 0.3.5
40
- #
41
- # @see http://ruby-doc.org/core/Object.html#method-i-inspect
42
- def inspect
43
- "#<#{self.class}:#{'0x0000%x' % (__id__ << 1)}#{__inspect}>"
44
- end
45
-
46
- # @!macro [attach] instance_of?(class)
47
- #
48
- # Determines if self is an instance of given class or module
49
- #
50
- # @param class [Class,Module] the class of module to verify
51
- #
52
- # @return [TrueClass,FalseClass] the result of the check
53
- #
54
- # @raise [TypeError] if the given argument is not of the expected types
55
- #
56
- # @since 1.3.2
57
- #
58
- # @see http://ruby-doc.org/core/Object.html#method-i-instance_of-3F
59
- define_method :instance_of?, ::Object.instance_method(:instance_of?)
60
-
61
- # @!macro [attach] is_a?(class)
62
- #
63
- # Determines if self is of the type of the object class or module
64
- #
65
- # @param class [Class,Module] the class of module to verify
66
- #
67
- # @return [TrueClass,FalseClass] the result of the check
68
- #
69
- # @raise [TypeError] if the given argument is not of the expected types
70
- #
71
- # @since 1.3.2
72
- #
73
- # @see http://ruby-doc.org/core/Object.html#method-i-is_a-3F
74
- define_method :is_a?, ::Object.instance_method(:is_a?)
75
-
76
- # @!macro [attach] kind_of?(class)
77
- #
78
- # Determines if self is of the kind of the object class or module
79
- #
80
- # @param class [Class,Module] the class of module to verify
81
- #
82
- # @return [TrueClass,FalseClass] the result of the check
83
- #
84
- # @raise [TypeError] if the given argument is not of the expected types
85
- #
86
- # @since 1.3.2
87
- #
88
- # @see http://ruby-doc.org/core/Object.html#method-i-kind_of-3F
89
- define_method :kind_of?, ::Object.instance_method(:kind_of?)
90
-
91
- # Alias for __id__
92
- #
93
- # @return [Fixnum] the object id
94
- #
95
- # @since 0.9.0
96
- #
97
- # @see http://ruby-doc.org/core/Object.html#method-i-object_id
98
- def object_id
99
- __id__
100
- end
101
-
102
- # Interface for pp
103
- #
104
- # @param printer [PP] the Pretty Printable printer
105
- # @return [String] the pretty-printable inspection of the object
106
- #
107
- # @since 0.9.0
108
- #
109
- # @see https://ruby-doc.org/stdlib/libdoc/pp/rdoc/PP.html
110
- def pretty_print(printer)
111
- printer.text(inspect)
112
- end
113
-
114
- # Returns true if responds to the given method.
115
- #
116
- # @return [TrueClass,FalseClass] the result of the check
117
- #
118
- # @since 0.3.5
119
- #
120
- # @see http://ruby-doc.org/core-2.2.1/Object.html#method-i-respond_to-3F
121
- def respond_to?(method_name, include_all = false)
122
- respond_to_missing?(method_name, include_all)
123
- end
124
-
125
- private
126
-
127
- # Must be overridden by descendants
128
- #
129
- # @since 0.3.5
130
- # @api private
131
- def respond_to_missing?(_method_name, _include_all)
132
- ::Kernel.raise ::NotImplementedError
133
- end
134
-
135
- # @since 0.3.5
136
- # @api private
137
- def __inspect
138
- end
139
- end
140
- end
141
- end