Closed ankane closed 2 years ago
Related, it looks like iRuby calls all the display methods, even if it only renders one.
class A
def to_html
puts "called to_html"
"HTML"
end
def to_png
puts "called to_png"
end
def to_iruby
puts "called to_png"
["text/plain", "IRUBY"]
end
end
A.new
Prints
called to_png
called to_html
called to_png
And renders HTML
It looks like one way around this is to define a to_iruby_mimebundle
method.
def to_iruby_mimebundle(**)
[{"text/plain" => "IRUBY"}, {}]
end
@ankane I changed the display routine in recent versions so that it follows the behavior of IPython's object formatter. It is necessary to support both Jupyter Notebook and JupyterLab, simultaneously.
@ankane I recommend using to_iruby_mimebundle
instead of to_iruby
now.
Hey @mrkn, thanks for the response and context! Will use that.
Hi, currently, if an object has methods like
to_html
orto_png
, they'll take precedence overto_iruby
. If an object hasto_iruby
defined, it seems like that should be preferred.Shows
HTML
instead ofIRUBY