* io.c (rb_open_file): encoding in mode string was ignored if perm is
[ruby-svn.git] / lib / irb / output-method.rb
blob301af7210e3e9338ffb962c2dd1fc77d46d8d144
2 #   output-method.rb - optput methods used by irb 
3 #       $Release Version: 0.9.5$
4 #       $Revision$
5 #       by Keiju ISHITSUKA(keiju@ruby-lang.org)
7 # --
9 #   
12 require "e2mmap"
14 module IRB
15   # OutputMethod
16   #   StdioOutputMethod
18   class OutputMethod
19     @RCS_ID='-$Id$-'
21     def print(*opts)
22       IRB.fail NotImplementError, "print"
23     end
25     def printn(*opts)
26       print opts.join(" "), "\n"
27     end
29     # extend printf
30     def printf(format, *opts)
31       if /(%*)%I/ =~ format
32         format, opts = parse_printf_format(format, opts)
33       end
34       print sprintf(format, *opts)
35     end
37     # %
38     # <flag>  [#0- +]
39     # <minimum field width> (\*|\*[1-9][0-9]*\$|[1-9][0-9]*)
40     # <precision>.(\*|\*[1-9][0-9]*\$|[1-9][0-9]*|)?
41     # #<length modifier>(hh|h|l|ll|L|q|j|z|t)
42     # <conversion specifier>[diouxXeEfgGcsb%] 
43     def parse_printf_format(format, opts)
44       return format, opts if $1.size % 2 == 1
45     end
47     def puts(*objs)
48       for obj in objs
49         print(*obj)
50         print "\n"
51       end
52     end
54     def pp(*objs)
55       puts(*objs.collect{|obj| obj.inspect})
56     end
58     def ppx(prefix, *objs)
59       puts(*objs.collect{|obj| prefix+obj.inspect})
60     end
62   end
64   class StdioOutputMethod<OutputMethod
65     def print(*opts)
66       STDOUT.print(*opts)
67     end
68   end
69 end