# frozen_string_literal: false
# output-method.rb - output methods used by irb
# $Release Version: 0.9.6$
# by Keiju ISHITSUKA(keiju@ruby-lang.org)
# An abstract output class for IO in irb. This is mainly used internally by
# IRB::Notifier. You can define your own output method to use with Irb.new,
class NotImplementedError < StandardError
super("Need to define `#{val}'")
# Open this method to implement your own output method, raises a
# NotImplementedError if you don't define #print in your own class.
raise NotImplementedError, "print"
# Prints the given +opts+, with a newline delimiter.
print opts.join(" "), "\n"
# Extends IO#printf to format the given +opts+ for Kernel#sprintf using
def printf(format, *opts)
format, opts = parse_printf_format(format, opts)
print sprintf(format, *opts)
# Returns an array of the given +format+ and +opts+ to be used by
# Kernel#sprintf, if there was a successful Regexp match in the given
# <minimum field width> (\*|\*[1-9][0-9]*\$|[1-9][0-9]*)
# <precision>.(\*|\*[1-9][0-9]*\$|[1-9][0-9]*|)?
# #<length modifier>(hh|h|l|ll|L|q|j|z|t)
# <conversion specifier>[diouxXeEfgGcsb%]
def parse_printf_format(format, opts)
return format, opts if $1.size % 2 == 1
# Calls #print on each element in the given +objs+, followed by a newline
# Prints the given +objs+ calling Object#inspect on each.
# See #puts for more detail.
puts(*objs.collect{|obj| obj.inspect})
# Prints the given +objs+ calling Object#inspect on each and appending the
# See #puts for more detail.
puts(*objs.collect{|obj| prefix+obj.inspect})
# A standard output printer
class StdioOutputMethod < OutputMethod
# Prints the given +opts+ to standard output, see IO#print for more