Skip to content

Commit 4579a3c

Browse files
committed
Use AmazingPrint::Inspector directly
Call AmazingPrint::Inspector.new().awesome() instead of the ai() method to avoid conflicts when awesome_print gem is also installed. Both gems define ai() on Object, causing unpredictable behavior.
1 parent 79d05a7 commit 4579a3c

4 files changed

Lines changed: 11 additions & 5 deletions

File tree

lib/ai-chat.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ def self.wrap_html(html)
55
html = html.gsub("<pre>", "<pre style=\"#{HTML_PRE_STYLE}\">")
66
html.respond_to?(:html_safe) ? html.html_safe : html
77
end
8+
9+
# Use AmazingPrint::Inspector directly to avoid conflicts with awesome_print gem
10+
# which also defines an `ai` method on Object
11+
def self.amazing_print(object, **options)
12+
AmazingPrint::Inspector.new(**options).awesome(object)
13+
end
814
end
915

1016
require_relative "ai/message"

lib/ai/chat.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@ def inspectable_attributes
228228
end
229229

230230
def inspect
231-
ai(plain: !$stdout.tty?, multiline: true)
231+
AI.amazing_print(self, plain: !$stdout.tty?, multiline: true)
232232
end
233233

234234
def to_html
235-
AI.wrap_html(ai(html: true, plain: true, multiline: true))
235+
AI.wrap_html(AI.amazing_print(self, html: true, plain: true, multiline: true))
236236
end
237237

238238
def pretty_inspect

lib/ai/items.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def pretty_print(q)
2929

3030
def build_output(html: false, plain: false)
3131
box = build_box
32-
items_output = data.ai(html: html, plain: plain, limit: 100, indent: 2, index: true)
32+
items_output = AI.amazing_print(data, html: html, plain: plain, limit: 100, indent: 2, index: true)
3333

3434
if html
3535
"<pre>#{box}</pre>\n#{items_output}"

lib/ai/message.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module AI
44
class Message < Hash
55
def inspect
6-
ai(plain: !$stdout.tty?, index: false)
6+
AI.amazing_print(self, plain: !$stdout.tty?, index: false)
77
end
88

99
def pretty_inspect
@@ -17,7 +17,7 @@ def pretty_print(q)
1717
end
1818

1919
def to_html
20-
AI.wrap_html(ai(html: true, plain: true, index: false))
20+
AI.wrap_html(AI.amazing_print(self, html: true, plain: true, index: false))
2121
end
2222
end
2323
end

0 commit comments

Comments
 (0)