[feature:trunk] let irb use pretty_inspect if possible

e$B1sF#$G$9!#e(B

irb e$B%a%s%F%[email protected]$5$se(B:

pretty_inspect e$B$,;HMQ2DG=$J$H$-$O!"e(Birb
e$B$N7k2L=PNO$K$=$l$r;H$&$N$Oe(B
e$B$I$&$G$7$g$&$+!#e(B

irb(main):001:0> [“foo bar baz”] * 6
=> [“foo bar baz”, “foo bar baz”, “foo bar baz”, “foo bar baz”, “foo
bar baz”, “foo bar baz”]
irb(main):002:0> require “pp”
=> true
irb(main):003:0> [“foo bar baz”] * 6
=> [“foo bar baz”,
“foo bar baz”,
“foo bar baz”,
“foo bar baz”,
“foo bar baz”,
“foo bar baz”]

e$BK\Ev$NL\E*$O!Ve(BObject#p e$B$HF1MM$Ke(B pp
e$B$K$b0z?t$rJV$7$F$[$7$$!W$H$$$&e(B
e$B0lG/A0$NOCe(B ([ruby-dev:34830] e$B!"e(B[ruby-dev:34833])
e$B$NB3$-$G!"EDCf$5$se(B
e$B$+$i$O!Ve(Birb e$B$,JQ$o$l$Pe(B pp
e$B$bJQ$($F$h$$!W$H$$$&>r7oIU:NO?$re(B (e$B$5$C$-e(B)
e$BLc$$$^$7$?!#e(B

e$B$h$m$7$/$*4j$$$7$^$9!#e(B

Index: lib/irb.rb

— lib/irb.rb (revision 23808)
+++ lib/irb.rb (working copy)
@@ -299,7 +299,13 @@

 def output_value
   if @context.inspect?
  •    printf @context.return_format, @context.last_value.inspect
    
  •    value = @context.last_value
    
  •    if value.respond_to?(:pretty_inspect)
    
  •      str = value.pretty_inspect.chomp
    
  •    else
    
  •      str = value.inspect
    
  •    end
    
  •    printf @context.return_format, str
     else
       printf @context.return_format, @context.last_value
     end

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

In [ruby-dev:38695] the message: “[ruby-dev:38695] [feature:trunk] let
irb use pretty_inspect if possible”, on Jun/21 23:06(JST) Yusuke ENDOH
writes:

e$B1sF#$G$9!#e(B

irb e$B%a%s%F%[email protected]$5$se(B:

pretty_inspect e$B$,;HMQ2DG=$J$H$-$O!"e(Birb e$B$N7k2L=PNO$K$=$l$r;H$&$N$Oe(B
e$B$I$&$G$7$g$&$+!#e(B

e$B$&!<$se(B. require e$B$7$F$"$k$He(B,
irbe$B$N?6$kIq$$$,JQ$o$k$N$O$I$&$+$H;W$$$^$9e(B
e$B$,e(B, irb e$B$Ge(B pp
e$B$J=PNO$r$9$k%b!<%I$,$"$C$F$bNI$$$h$J!<$H$O;W$C$F$$$^$7$?e(B.

e$B%3%^%s%I%i%$%s%*%W%7%g%s$b$7$/$Oe(B, .irbrc e$B$G$Ne(B
IRB.CONFe$B$N;XDj$Ge(B pp e$B$J=Pe(B
e$BNO$K$J$k$H$$$&$N$G$bNI$$$G$9$h$Me(B?

irb --inspect pp

e$B$Ge(B pp e$B$J=PNO$r$9$k$+$s$8$G$9e(B.

e$BK\Ev$NL\E*$O!Ve(BObject#p e$B$HF1MM$Ke(B pp e$B$K$b0z?t$rJV$7$F$[$7$$!W$H$$$&e(B
e$B0lG/A0$NOCe(B ([ruby-dev:34830] e$B!"e(B[ruby-dev:34833]) e$B$NB3$-$G!"EDCf$5$se(B
e$B$+$i$O!Ve(Birb e$B$,JQ$o$l$Pe(B pp e$B$bJQ$($F$h$$!W$H$$$&>r7oIU:NO?$re(B (e$B$5$C$-e(B)
e$BLc$$$^$7$?!#e(B

e$B$"!<e(B. e$B$J$k$[$Ie(B,

irb(main):006:0> pp 1
1
=> nil

e$B$Ge(B e$B0z?t$rJV$9$h$&$K$J$k$He(B,
2e$B=E$KI=<($7$F$7$^$&$+$i$G$9$Me(B.

__
---------------------------------------------------->> [email protected](B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

In [ruby-dev:38703] the message: “[ruby-dev:38703] Re: [feature:trunk]
let irb use pretty_inspect if possible”, on Jun/23 05:47(JST) Yusuke
ENDOH writes:

e$B1sF#$G$9!#e(B

irb --inspect pp
e$B$Ge(B pp e$B$J=PNO$r$9$k$+$s$8$G$9e(B.

e$B$?$V$s$$$$$H;W$$$^$9!#[email protected]!"$I$&$;e(B pp e$B$KFC2=$9$k$N$J$i!"e(B–pp e$B$J$I$Ke(B
e$B$7$?$iC;$/$F$&$l$7$$$+$b$7$l$J$$$G$9!#$3$s$J%*%W%7%g%s$O$I$&$G$7$g$&$+!#e(B

–inspect-method foo: e$B7k2L=PNO$N:]!"e(Binspect e$B$NBe$o$j$Ke(B foo e$B$rMQ$$$ke(B
–pp: -rpp --inspect-method=pretty_inspect e$B$HF1$88z2Le(B

e$B$3$NJ}?K$N%Q%C%A$r:n$C$F$$^$7$?!#e(B
irb e$B$N9%$
$d:nK!$K$"$o$J$+$C$?$i$9$_$^$;$s!#e(B

e$B$o$6$o$6%Q%C%A$r:n$C$F$/[email protected]$5$j$"$j$,$H$&$4$6$$$^$9e(B.

e$B<B$O$9$G$K$3$A$i$G$b:n$C$F$$$Fe(B, --inspect pp
e$B0J30$K$b%V%m%C%/$,;XDj$Ge(B
e$B$-$Fe(B:

irb -r yaml --inspect “{|v| YAML.dump(v)}”

e$B$J$s$F;XDj$b$G$-$k$h$&$K$7$^$7$?e(B.

e$B$^$"e(B, e$B;H$&?M$O$$$J$$$H;W$$$^$9$,e(B(^^;;

pp(pretty_print)e$B$O$H$b$+$/e(B,
e$B%%V%8%’%/%H$KBP$9$kD>@$N%a%=%C%I$O>-MhEe(B
e$B$K$b$"$^$j=P$F$-$=$&$b$J$$5$$,$7$^$9e(B.

e$B$"$He(B, e$B%3%^%s%I0z?t$K4X$7$F$G$9$,e(B,
ppe$B$rHs>o$KNI$/;H$&[email protected]$C$?$ie(B, .irbrc
e$B$Ke(B

IRB.conf[:INSPECT_MODE] = :pp

[email protected]$1$l$P%3%^%s%I0z?t$GEO$9I,MW$O$J$/$J$j$^$9$N$Ge(B,
e$BC;$$$N$K$"e(B
e$B$^[email protected]$o$i$J$/$F$bNI$$$N$G$O$J$$$+$H;W$$$^$9$,e(B?

e$B$$$+$,$G$7$g$&e(B?

__
---------------------------------------------------->> [email protected](B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e$B1sF#$G$9!#e(B

2009/06/22 0:43 e$B$Ke(B [email protected]=<ye(B[email protected]
e$B$5$s$O=q$-$^$7$?e(B:

e$B$&!<$se(B. require e$B$7$F$"$k$He(B, irbe$B$N?6$kIq$$$,JQ$o$k$N$O$I$&$+$H;W$$$^$9e(B
e$B$,e(B, irb e$B$Ge(B pp e$B$J=PNO$r$9$k%b!<%I$,$"$C$F$bNI$$$h$J!<$H$O;W$C$F$$$^$7$?e(B.

e$B$O$$!#e(B

e$B%3%^%s%I%i%$%s%*%W%7%g%s$b$7$/$Oe(B, .irbrc e$B$G$Ne(B IRB.CONFe$B$N;XDj$Ge(B pp e$B$J=Pe(B
e$BNO$K$J$k$H$$$&$N$G$bNI$$$G$9$h$Me(B?

irb --inspect pp

e$B$Ge(B pp e$B$J=PNO$r$9$k$+$s$8$G$9e(B.

e$B$?$V$s$$$$$H;W$$$^$9!#[email protected]!"$I$&$;e(B pp e$B$KFC2=$9$k$N$J$i!"e(B–pp
e$B$J$I$Ke(B
e$B$7$?$iC;$/$F$&$l$7$$$+$b$7$l$J$$$G$9!#$3$s$J%*%W%7%g%s$O$I$&$G$7$g$&$+!#e(B

–inspect-method foo: e$B7k2L=PNO$N:]!"e(Binspect e$B$NBe$o$j$Ke(B foo
e$B$rMQ$$$ke(B
–pp: -rpp --inspect-method=pretty_inspect e$B$HF1$88z2Le(B

e$B$3$NJ}?K$N%Q%C%A$r:n$C$F$$^$7$?!#e(B
irb e$B$N9%$
$d:nK!$K$"$o$J$+$C$?$i$9$_$^$;$s!#e(B

Index: lib/irb/context.rb

— lib/irb/context.rb (revision 23826)
+++ lib/irb/context.rb (working copy)
@@ -35,6 +35,7 @@

   @use_readline = IRB.conf[:USE_READLINE]
   @inspect_mode = IRB.conf[:INSPECT_MODE]
  •  @inspect_method = IRB.conf[:INSPECT_METHOD]
    
     self.math_mode = IRB.conf[:MATH_MODE] if IRB.conf[:MATH_MODE]
     self.use_tracer = IRB.conf[:USE_TRACER] if IRB.conf[:USE_TRACER]
    

@@ -116,6 +117,7 @@

 attr_reader :use_readline
 attr_reader :inspect_mode
  • attr_reader :inspect_method

    attr_reader :prompt_mode
    attr_accessor :prompt_i
    Index: lib/irb/lc/ja/help-message
    ===================================================================
    — lib/irb/lc/ja/help-message (revision 23826)
    +++ lib/irb/lc/ja/help-message (working copy)
    @@ -18,6 +18,9 @@
    -E enc ruby -E e$B$HF1$8e(B.
    –inspect
    e$B7k2L=PNO$Ke(Binspecte$B$rMQ$$$ke(B(bce$B%b!<%I0J30$O%G%U%)%k%He(B).
    –noinspect e$B7k2L=PNO$Ke(Binspecte$B$rMQ$$$J$$e(B.

  • –inspect-method method-name

  •    e$B7k2L=PNO$N:]e(B, 
    

inspecte$B$NBe$o$j$Ke(Bmethod-namee$B$rMQ$$$ke(B.

  • –pp -rpp --inspect-method=pretty_inspect e$B$HF1$8e(B.
    –readline readlinee$B%i%$%V%i%j$rMxMQ$9$ke(B.
    –noreadline readlinee$B%i%$%V%i%j$rMxMQ$7$J$$e(B.
    –prompt prompt-mode/–prompt-mode prompt-mode
    Index: lib/irb/lc/help-message
    ===================================================================
    — lib/irb/lc/help-message (revision 23826)
    +++ lib/irb/lc/help-message (working copy)
    @@ -19,6 +19,9 @@
    -E enc Same as ruby -E
    –inspect Use `inspect’ for output (default except for bc mode)
    –noinspect Don’t use inspect for output

  • –inspect-method method-name

  •    Use method-name instead of `inspect' for output
    
  • –pp Identical to -rpp --inspect-method=pretty_inspect
    –readline Use Readline extension module
    –noreadline Don’t use Readline extension module
    –prompt prompt-mode
    Index: lib/irb/init.rb
    ===================================================================
    — lib/irb/init.rb (revision 23826)
    +++ lib/irb/init.rb (working copy)
    @@ -45,6 +45,7 @@
    @CONF[:MATH_MODE] = false
    @CONF[:USE_READLINE] = false unless defined?(ReadlineInputMethod)
    @CONF[:INSPECT_MODE] = nil

  • @CONF[:INSPECT_METHOD] = “inspect”
    @CONF[:USE_TRACER] = false
    @CONF[:USE_LOADER] = false
    @CONF[:IGNORE_SIGINT] = true
    @@ -148,6 +149,11 @@
    @CONF[:INSPECT_MODE] = true
    when “–noinspect”
    @CONF[:INSPECT_MODE] = false

  •  when /^--inspect-method(?:=(.+))?/
    
  • @CONF[:INSPECT_METHOD] = $1 || ARGV.shift

  •  when "--pp"
    
  • @CONF[:LOAD_MODULES].push “pp”

  • @CONF[:INSPECT_METHOD] = “pretty_inspect”
    when “–readline”
    @CONF[:USE_READLINE] = true
    when “–noreadline”
    Index: lib/irb.rb
    ===================================================================
    — lib/irb.rb (revision 23826)
    +++ lib/irb.rb (working copy)
    @@ -299,7 +299,8 @@

    def output_value
    if @context.inspect?

  •    printf @context.return_format, @context.last_value.inspect
    
  •    str = @context.last_value.send(@context.inspect_method)
    
  •    printf @context.return_format, str
     else
       printf @context.return_format, @context.last_value
     end

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

trunke$B$K%j%j!<%9$7$^$7$?e(B.

irb --inspect pp

e$B$Ge(B pp e$B$r;H$&$h$&$K$J$j$^$9e(B. e$B$"$He(B, e$B$*$^$1$Ge(B,
yaml e$B$He(B marshal e$B$b$D$1$Fe(B
e$B$"$j$^$9e(B(^^;;;

e$B;H$$J}e(B.

  • e$B%3%^%s%I%i%$%se(B

% irb --inspect [raw|p|pp|yaml|marshal|…]

e$B$^$?$Oe(B, e$B%V%m%C%/;XDj$Ge(B

% irb -r yaml --inspect “{|v| YAML.dump(v)}”

  • e$B<B9TCf$G$NJQ99e(B

irb(main):001:0> conf.inspect_mode = :yaml

  • .irbrc e$B$G%G%U%)%k%H$N?6$kIq$$$rJQ$($ke(B

IRB.conf[:INSPECT_MODE] = [:raw|:p|:pp|:yaml|:marshal|…]

  • e$B%f!<%6!<Dj5A%b!<%Ie(B

IRB::INSPECTORS.def_inspector(mode_names, init_proc, &inspect_block)

e$BNce(B)

.irbrce$B$Ge(B

IRB::INSPECTORS.def_inspector([:test]){|v| v.to_s*2}

e$B$H$7e(B,

% irb --inspect test

e$B$G<B9T$9$ke(B.

e$B$3$s$J46$8$K$J$j$^$7$?e(B.

In [ruby-dev:38707] the message: “[ruby-dev:38707] Re: [feature:trunk]
let irb use pretty_inspect if possible”, on Jun/24 01:08(JST)
Yusuke ENDOH writes:

e$B$$$9$P$i$7$$!#e(B

e$B;d$N$h$&$K$o$,$^$^$J?M$Oe(B

irb(main):001:0> pp obj; nil

e$B$H$7$F$/$l!"$H$$$&$3$H$G!#:#$G$be(B ary.each {|x| …; p x } e$B$H$+$9$k$H$-$Oe(B
e$B:G8e$Ke(B ; nil e$B$J$I$r$D$1$k$3$H$,B?$$$G$9$7$M!#e(B


Yusuke ENDOH [email protected]

__
---------------------------------------------------->> [email protected](B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:38744] Re: [feature:trunk] let irb use
pretty_inspect if possible”
on Tue, 7 Jul 2009 22:42:04 +0900, [email protected]
([email protected]=<ye(B) writes:

|trunke$B$K%j%j!<%9$7$^$7$?e(B.
|
|irb --inspect pp
|
|e$B$Ge(B pp e$B$r;H$&$h$&$K$J$j$^$9e(B. e$B$"$He(B, e$B$*$^$1$Ge(B, yaml e$B$He(B marshal e$B$b$D$1$Fe(B
|e$B$"$j$^$9e(B(^^;;;

irb/inspector.rbe$B$,%A%’%C%/%$%s$5$l$F$$$J$$$h$&$J!#e(B

e$B1sF#$G$9!#e(B

2009/06/24 0:25 e$B$Ke(B [email protected]=<ye(B[email protected]
e$B$5$s$O=q$-$^$7$?e(B:

e$B<B$O$9$G$K$3$A$i$G$b:n$C$F$$$Fe(B, --inspect pp e$B0J30$K$b%V%m%C%/$,;XDj$Ge(B
e$B$-$Fe(B:

irb -r yaml --inspect “{|v| YAML.dump(v)}”

e$B$J$s$F;XDj$b$G$-$k$h$&$K$7$^$7$?e(B.

e$B$$$9$P$i$7$$!#e(B

pp(pretty_print)e$B$O$H$b$+$/e(B, e$B%%V%8%’%/%H$KBP$9$kD>@$N%a%=%C%I$O>-MhEe(B
e$B$K$b$"$^$j=P$F$-$=$&$b$J$$5$$,$7$^$9e(B.

e$B3N$+$K$=$&$G$9$M!#e(B

e$B$"$He(B, e$B%3%^%s%I0z?t$K4X$7$F$G$9$,e(B, ppe$B$rHs>o$KNI$/;H$&[email protected]$C$?$ie(B, .irbrc
e$B$Ke(B

IRB.conf[:INSPECT_MODE] = :pp

[email protected]$1$l$P%3%^%s%I0z?t$GEO$9I,MW$O$J$/$J$j$^$9$N$Ge(B, e$BC;$$$N$K$"e(B
e$B$^[email protected]$o$i$J$/$F$bNI$$$N$G$O$J$$$+$H;W$$$^$9$,e(B?

e$B8D?ME*[email protected]_Dj$O6KNO$7$J$$GI$J$N$G!"C;$$J}$,4r$7$$$J!<$H$O;W$$$^$9!#$,!"e(B
irb
e$B$,%+%9%?%^%$%:$r?d>)$7$F$$$kJ70O5$$O46$8<h$C$F$$$^$9$N$G$=$l$G$$$$$He(B
e$B;W$$$^$9!#e(B

[email protected]_Dj$O$7$?$/$J$$$1$Ie(B pp
e$B$O;H$$$?$$!"M>7W$JI=<($O$7$F$[$7$/$J$$!W$H$$$&e(B
e$B;d$N$h$&$K$o$,$^$^$J?M$Oe(B

irb(main):001:0> pp obj; nil

e$B$H$7$F$/$l!"$H$$$&$3$H$G!#:#$G$be(B ary.each {|x| …; p x }
e$B$H$+$9$k$H$-$Oe(B
e$B:G8e$Ke(B ; nil e$B$J$I$r$D$1$k$3$H$,B?$$$G$9$7$M!#e(B

e$B$1$$$8$e!w$$$7$D$+$G$9e(B.

In [ruby-dev:38746] the message: “[ruby-dev:38746] Re: [feature:trunk]
let irb use pretty_inspect if possible”, on Jul/08 13:18(JST)
Yukihiro M. writes:

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

|trunke$B$K%j%j!<%9$7$^$7$?e(B.
|
|irb --inspect pp
|
|e$B$Ge(B pp e$B$r;H$&$h$&$K$J$j$^$9e(B. e$B$"$He(B, e$B$*$^$1$Ge(B, yaml e$B$He(B marshal e$B$b$D$1$Fe(B
|e$B$"$j$^$9e(B(^^;;;

irb/inspector.rbe$B$,%A%’%C%/%$%s$5$l$F$$$J$$$h$&$J!#e(B

e$B?=$7Lu$J$$e(B. e$B%A%’%C%/%$%s$7$^$7$?e(B.

__
---------------------------------------------------->> [email protected](B
e$B7=<ye(B <<—
---------------------------------->> e-mail: [email protected] <<—

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs