hanami-utils 2.0.0.alpha2 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,144 +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
- #
43
- # rubocop:disable Style/FormatStringToken
44
- def inspect
45
- "#<#{self.class}:#{'0x0000%x' % (__id__ << 1)}#{__inspect}>"
46
- end
47
- # rubocop:enable Style/FormatStringToken
48
-
49
- # @!macro [attach] instance_of?(class)
50
- #
51
- # Determines if self is an instance of given class or module
52
- #
53
- # @param class [Class,Module] the class of module to verify
54
- #
55
- # @return [TrueClass,FalseClass] the result of the check
56
- #
57
- # @raise [TypeError] if the given argument is not of the expected types
58
- #
59
- # @since 1.3.2
60
- #
61
- # @see http://ruby-doc.org/core/Object.html#method-i-instance_of-3F
62
- define_method :instance_of?, ::Object.instance_method(:instance_of?)
63
-
64
- # @!macro [attach] is_a?(class)
65
- #
66
- # Determines if self is of the type of the object class or module
67
- #
68
- # @param class [Class,Module] the class of module to verify
69
- #
70
- # @return [TrueClass,FalseClass] the result of the check
71
- #
72
- # @raise [TypeError] if the given argument is not of the expected types
73
- #
74
- # @since 1.3.2
75
- #
76
- # @see http://ruby-doc.org/core/Object.html#method-i-is_a-3F
77
- define_method :is_a?, ::Object.instance_method(:is_a?)
78
-
79
- # @!macro [attach] kind_of?(class)
80
- #
81
- # Determines if self is of the kind of the object class or module
82
- #
83
- # @param class [Class,Module] the class of module to verify
84
- #
85
- # @return [TrueClass,FalseClass] the result of the check
86
- #
87
- # @raise [TypeError] if the given argument is not of the expected types
88
- #
89
- # @since 1.3.2
90
- #
91
- # @see http://ruby-doc.org/core/Object.html#method-i-kind_of-3F
92
- define_method :kind_of?, ::Object.instance_method(:kind_of?)
93
-
94
- # Alias for __id__
95
- #
96
- # @return [Fixnum] the object id
97
- #
98
- # @since 0.9.0
99
- #
100
- # @see http://ruby-doc.org/core/Object.html#method-i-object_id
101
- def object_id
102
- __id__
103
- end
104
-
105
- # Interface for pp
106
- #
107
- # @param printer [PP] the Pretty Printable printer
108
- # @return [String] the pretty-printable inspection of the object
109
- #
110
- # @since 0.9.0
111
- #
112
- # @see https://ruby-doc.org/stdlib/libdoc/pp/rdoc/PP.html
113
- def pretty_print(printer)
114
- printer.text(inspect)
115
- end
116
-
117
- # Returns true if responds to the given method.
118
- #
119
- # @return [TrueClass,FalseClass] the result of the check
120
- #
121
- # @since 0.3.5
122
- #
123
- # @see http://ruby-doc.org/core-2.2.1/Object.html#method-i-respond_to-3F
124
- def respond_to?(method_name, include_all = false)
125
- respond_to_missing?(method_name, include_all)
126
- end
127
-
128
- private
129
-
130
- # Must be overridden by descendants
131
- #
132
- # @since 0.3.5
133
- # @api private
134
- def respond_to_missing?(_method_name, _include_all)
135
- ::Kernel.raise ::NotImplementedError
136
- end
137
-
138
- # @since 0.3.5
139
- # @api private
140
- def __inspect
141
- end
142
- end
143
- end
144
- end