/
basic_object.rb
82 lines (75 loc) · 2.01 KB
/
basic_object.rb
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
module Hanami
module Utils
# BasicObject
#
# @since 0.3.5
class BasicObject < ::BasicObject
# Return the class for debugging purposes.
#
# @since 0.3.5
#
# @see http://ruby-doc.org/core/Object.html#method-i-class
def class
(class << self; self; end).superclass
end
# Bare minimum inspect for debugging purposes.
#
# @return [String] the inspect string
#
# @since 0.3.5
#
# @see http://ruby-doc.org/core/Object.html#method-i-inspect
#
# rubocop:disable Style/FormatString
# rubocop:disable Style/FormatStringToken
def inspect
"#<#{self.class}:#{'0x0000%x' % (__id__ << 1)}#{__inspect}>"
end
# rubocop:enable Style/FormatStringToken
# rubocop:enable Style/FormatString
# Alias for __id__
#
# @return [Fixnum] the object id
#
# @since 0.9.0
#
# @see http://ruby-doc.org/core/Object.html#method-i-object_id
def object_id
__id__
end
# Interface for pp
#
# @param printer [PP] the Pretty Printable printer
# @return [String] the pretty-printable inspection of the object
#
# @since 0.9.0
#
# @see https://ruby-doc.org/stdlib/libdoc/pp/rdoc/PP.html
def pretty_print(printer)
printer.text(inspect)
end
# Returns true if responds to the given method.
#
# @return [TrueClass,FalseClass] the result of the check
#
# @since 0.3.5
#
# @see http://ruby-doc.org/core-2.2.1/Object.html#method-i-respond_to-3F
def respond_to?(method_name, include_all = false)
respond_to_missing?(method_name, include_all)
end
private
# Must be overridden by descendants
#
# @since 0.3.5
# @api private
def respond_to_missing?(_method_name, _include_all)
::Kernel.raise ::NotImplementedError
end
# @since 0.3.5
# @api private
def __inspect
end
end
end
end