Skip to content

Ultimate YAML in IRb and all the think alikes

After I realized that I want to switch from default inspect output in IRB to YAML output, I googled and found this Secrets of the Rails Console Ninjas from Amy Hoy which suggested to use y method, then Geoffrey Grosenbach suggests class Object; def inspect; y self; end; end, but that would break for explicitly defined inspect’s, oh no! Evil-mokey-patch to the rescue:
IRB.CurrentContext.irb.instance_eval do
  def output_value
    printf @context.return_format, y(@context.last_value)
  end
end
blog comments powered by Disqus