[提案] Kernel#p をもっと便利に

e$B1sF#PR2p$H?=$7$^$9!#e(B

e$BF|:"$+$i;W$C$F$$$?$3$H$rDs0F$7$F$_$^$9!#e(B

p e$B$Oe(B nil
e$B$G$O$J$/0z?t$rJV$7$F$/$l$k$H4r$7$$$H;W$$$^$9!#Nc$($Pe(B:

def foo

str.gsub()
end

e$B$H$$$&%3!<%I$r%G%P%C%0$7$F$$$F!"JV$jCM$r8+$?$/$J$C$?$H$-e(B

def foo

x=str.gsub()
p x
x
end

e$B$H=q$+$J$$$H$$$1$J$$$N$,e(B

def foo

p str.gsub()
end

e$B$Ne(B 2 e$B%9%H%m!<%/$G:Q$_$^$9!#e(B

e$B$^$?!"4X?t7A<0$G$J$$7A<0$G8F$S=P$7$?>l9g!"e(Bself e$B$r=PNO$7!"e(B
self e$B$rJV$9$H$$$&$N$b$$$$$H;W$$$^$9!#e(B

def foo

str.gsub().p
end

Ruby [email protected]$1$G6a;wE*$K<B8=$9$k$J$i0J2<$N$h$&$J46$8$G$7$g$&$+!#e(B

class Object
def p(*a)
if a.empty? then
Kernel.p(self)
self
else
Kernel.p(*a)
a.last
end
end
end

e$B5sF0$NJQ99$G$O$"$j$^$9$,!"e(Bp
e$B$O%G%P%C%0MQES$N%a%=%C%[email protected]$H;W$o$l$k$N$Ge(B
e$B<B32$O$[$%<%[email protected]$H;W$$$^$9!#e(B

1 e$BJ8;z$Ge(B nil e$B$r:n$kJ}K!$,$J$/$J$j$=$&$J$N$Ge(B codegolf

e$B$G$O:$$k$+$b!)e(B

e$B$h$m$7$/$48!F$$/[email protected]$5$$!#e(B

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

In message Re: [ruby-dev:29736] [e$BDs0Fe(B] Kernel#p
e$B$r$b$C$HJXMx$Ke(B
on Thu, 2 Nov 2006 02:47:32 +0900, Yusuke ENDOH [email protected]
writes:

|p e$B$Oe(B nil e$B$G$O$J$/0z?t$rJV$7$F$/$l$k$H4r$7$$$H;W$$$^$9!#e(B

p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B
e$B:G=i$N0z?tCM!)e(B e$B:G8e$N0z?tCM!)e(B nile$B!)e(B

e$B;d$Ne(B motivation example e$B$G$Oe(B
p e$B$KJ#?t$N0z?t$r<h$i$;$k$3$H$O$J$5$=$&$J$N$G!"$I$l$G$b$$$$$G$9!#e(B

e$B4X?t$N:G8e$Ke(B a, b e$B$H$O=q$1$J$$$G$9$h$M!)e(B

e$B$^$"!"$=$&$+$b$7$l$^$;$s$,!">/$J$/$H$be(B1.8e$B$G$O$d$a$F$*$$$?J}e(B
e$B$,NI$$$G$7$g$&$M!#e(B

e$B$=$&$G$9$M!#e(B
[email protected]?ME*$J463P$G$O!"$=$3$^$G5$$K$7$J$/$F$b$$$$5$$b$7$^$9!#e(B
e$B8=>u$Ge(B p e$B$NJV$jCM$r;H$&[email protected]$Oe(B

  • iorcc
  • codegolf
  • e$BL50U<1$K;H$C$F$$$ke(B ([email protected]:_E*$J%P%0e(B)
    e$B$/$i$$$7$+;W$$$D$-$^$;$s$N$G!#e(B

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

In message Re: [ruby-dev:29741] Re: [e$BDs0Fe(B] Kernel#p
e$B$r$b$C$HJXMx$Ke(B
on Thu, 2 Nov 2006 10:42:01 +0900, KURODA Hiraku
[email protected] writes:

|p e$B$,J#?t$N0z?t$r$H$C$?>l9g!"D>@\G[Ns$K$7$FJV$9$N$O$I$&$G$7$g$&$+e(B?

e$B0z?t$N?t$K$h$C$FLa$jCM$,G[[email protected]$C$?$j$=$&$G$J$+$C$?$j$9$k$N$O!"e(B
e$B7h$7$F;H$$$d$9$/$J$$$h$&$K;W$$$^$9!#e(B

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

Yukihiro M. wrote:

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

In message Re: [ruby-dev:29741] Re: [e$BDs0Fe(B] Kernel#p e$B$r$b$C$HJXMx$Ke(B
on Thu, 2 Nov 2006 10:42:01 +0900, KURODA Hiraku [email protected] writes:

|p e$B$,J#?t$N0z?t$r$H$C$?>l9g!"D>@\G[Ns$K$7$FJV$9$N$O$I$&$G$7$g$&$+e(B?

e$B0z?t$N?t$K$h$C$FLa$jCM$,G[[email protected]$C$?$j$=$&$G$J$+$C$?$j$9$k$N$O!"e(B
e$B7h$7$F;H$$$d$9$/$J$$$h$&$K;W$$$^$9!#e(B

e$B$9$_$^$;$s!"3N$+$K$=$&$G$7$?!#e(B
[email protected]$OE12s$5$;$F$/[email protected]$5$$!#e(B

e$B:G=ie(B(e$B$^$?:G8ee(B)e$B$N0z?t$rJV$9$H$$$&1sF#$5$s$N%"%$%G%"<+BN$O!"e(B

[email protected]$1$k$H4r$7$$$G$9e(B

Yuguie$B$H?=$7$^$9!#e(B

06/11/02 e$B$Ke(B Yukihiro M.[email protected]
e$B$5$s$O=q$-$^$7$?e(B:

In message Re: [ruby-dev:29741] Re: [e$BDs0Fe(B] Kernel#p e$B$r$b$C$HJXMx$Ke(B
on Thu, 2 Nov 2006 10:42:01 +0900, KURODA Hiraku [email protected] writes:

|p e$B$,J#?t$N0z?t$r$H$C$?>l9g!"D>@\G[Ns$K$7$FJV$9$N$O$I$&$G$7$g$&$+e(B?

e$B0z?t$N?t$K$h$C$FLa$jCM$,G[[email protected]$C$?$j$=$&$G$J$+$C$?$j$9$k$N$O!"e(B
e$B7h$7$F;H$$$d$9$/$J$$$h$&$K;W$$$^$9!#e(B

return a,be$B$r%G%P%C%0;~$Ke(Breturn p
a,[email protected]$G!"$I$&$;CM$rJV$9$J$iG[Ns$rJV$7$F$/$l$k$H4r$7$$$G$9!#e(B
e$B;d$N>l9g!"@Q6KE*$Ke(Bpe$B$KJ#?t$NCM$rEO$7$?$$6ILL$O$3$l0J30$K$"$j$^$;$s!#e(B

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

return a,be$B$r%G%P%C%0;~$Ke(Breturn p a,[email protected]$G!"$I$&$;CM$rJV$9$J$iG[Ns$rJV$7$F$/$l$k$H4r$7$$$G$9!#e(B

return a, b
e$B$,$=$&$$$&5sF0$r<h$k$H$k$N$J$i!"$"$o$;$k$N$,$$$$$+$b$G$9$M!#e(B
return e$B;H$o$J$$GI$J$N$G5$$,IU$-$^$;$s$G$7$?!#e(B
e$BB?=EBeF~$H$"$o$;$F!"B?CM4X?t$C$]$$I=8=$r2DG=$K$9$k$?$a$N;EMM$G$7$g$&$+!#e(B

e$B$G$be(B return p a, b e$B$Oe(B warning

e$B$,=P$k$N$G!"8D?ME*$K$O=q$+$J$$$G$9e(B ^^;

Gimitee$B$H$$$$$^$9!#e(B

e$B3N$+$Ke(Bpe$B$,La$jCM$rJV$9$N$OJXMx$=$&$G$9$M!#e(B

|p e$B$,J#?t$N0z?t$r$H$C$?>l9g!"D>@\G[Ns$K$7$FJV$9$N$O$I$&$G$7$g$&$+e(B?

e$B0z?t$N?t$K$h$C$FLa$jCM$,G[[email protected]$C$?$j$=$&$G$J$+$C$?$j$9$k$N$O!"e(B
e$B7h$7$F;H$$$d$9$/$J$$$h$&$K;W$$$^$9!#e(B

e$B!VLa$jCM$rJV$9$H$3$m$K64$a$k$N$,JXMx!W$H$$$&F05!$G$9$+$i!e(B
Rubye$B$Ne(Breturne$B$,!V0z?t$N?t$K$h$C$FLa$jCM$,G[[email protected]$C$?$je(B
e$B$=$&$G$J$+$C$?$j$9$k!W0J>e!$=$l$K9g$o$;$k$N$,$$$$$h$&$Je(B
e$B5$$,$9$k$N$G$9$,!D!#e(B

e$B!t$H$$$&$+!"e(Breturn 1, 2e$B$Ge(B[1,
2]e$B$rJV$;$k$N$O=i<*$G$7$?!#e(B
e$B!te(Breturne$B$r>JN,$7$Fe(B1, [email protected]$HBLL$J$s$G$9$M!D!#e(B

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

e$B$^$?!"4X?t7A<0$G$J$$7A<0$G8F$S=P$7$?>l9g!"e(Bself e$B$r=PNO$7!"e(B
self e$B$rJV$9$H$$$&$N$b$$$$$H;W$$$^$9!#e(B

def foo

str.gsub().p
end

e$B$3$C$A$KBP$9$k$40U8+$48!F$$b4|BT$7$F$^$9e(B ^^

[email protected]$O!"%a%=%C%I%A%%$%s$N%G%P%C%0$,4JC1$K$J$k$3$H$G$9!#Nc$($Pe(B

ary.map{}.join("\n").gsub()

e$B$H=q$$$F$$$?$H$3$m$G!"e(Bmap e$B$^$GI>2A$7$?CM$r8+$?$/$J$C$?$H$-e(B

p x=ary.map{}
x.join("\n").gsub()

e$B$H=q$+$J$1$l$P$J$i$J$$$N$,e(B

ary.map{}.p.join("\n").gsub()

e$B$G:Q$_$^$9!#e(B

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

1.9 e$B$G<BAu$7$F$_$^$7$?!#e(B
e$BJ#?t0z?t$N$H$-$OG[Ns$rJV$9$h$&$K$7$F$$$^$9!#e(B

make check e$B$N7k2L$OJQ$o$j$^$;$s$G$7$?e(B (17F4E, i686-linux, Debian
sarge) e$B!#e(B

[email protected]$7e(B HEAD e$B$G$Oe(B make install e$B$de(B make check

e$B$,F0:n$7$J$+$C$?$N$G!"e(B

eval.c e$B$re(B 1.954 e$B$^$GLa$7$F$$$^$9!#e(B

e$B$h$m$7$/$48!F$$/[email protected]$5$$!#e(B

ruby.org/io.c 2006-10-17 08:07:07.000000000 +0900
+++ ruby/io.c 2006-11-13 01:28:31.000000000 +0900
@@ -3908,15 +3908,27 @@ rb_p(VALUE obj) /* for debug print withi

static VALUE
-rb_f_p(int argc, VALUE *argv)
+rb_f_p(int argc, VALUE *argv, VALUE self)
{
int i;

  • VALUE ret;
  • for (i=0; i<argc; i++) {
  •   rb_p(argv[i]);
    
  • if (argc == 0) {
  •   rb_p(self);
    
  •   ret = self;
    
  • } else {
  •   for (i=0; i<argc; i++) {
    
  •       rb_p(argv[i]);
    
  •   }
    
  •   if (argc == 1) {
    
  •       ret = argv[0];
    
  •   }
    
  •   else {
    
  •       ret = rb_ary_new4(argc, argv);
    
  •   }
    
    }
    if (TYPE(rb_stdout) == T_FILE) {
    rb_io_flush(rb_stdout);
    }
  • return Qnil;
  • return ret;
    }

@@ -5626,5 +5638,5 @@ Init_IO(void)
rb_define_global_function("`", rb_f_backquote, 1);

  • rb_define_global_function(p, rb_f_p, -1);
  • rb_define_method(rb_mKernel, p, rb_f_p, -1);
    rb_define_method(rb_mKernel, display, rb_obj_display, -1);

Yusuke ENDOH wrote:

e$B1sF#$H?=$7$^$9!#e(B

e$BH>G/0J>e7P$C$F$7$^$$$^$7$?$,!"$3$NDs0Fe(B (ruby-dev:29736) [email protected]$5$l$?e(B
e$B$N$G$7$g$&$+!#e(B
e$B$3$l$,$"$k$H%G%P%C%0$,$h$j0lAX3Z$K$J$k$N$G!"$48!F$$/[email protected]$5$l$P9,$$$G$9!#e(B

1.9e$B$K$Oe(BObject#tape$B$H$$$&$N$,DI2C$5$l$F$$$k$h$&$G$9!#e(B

e$BH>G/0J>e7P$C$F$7$^$$$^$7$?$,!"$3$NDs0Fe(B (ruby-dev:29736) [email protected]$5$l$?e(B
e$B$N$G$7$g$&$+!#e(B
e$B$3$l$,$"$k$H%G%P%C%0$,$h$j0lAX3Z$K$J$k$N$G!"$48!F$$/[email protected]$5$l$P9,$$$G$9!#e(B

1.9e$B$K$Oe(BObject#tape$B$H$$$&$N$,DI2C$5$l$F$$$k$h$&$G$9!#e(B

e$B$J$k$[$I!"$=$l$OCN$j$^$;$s$G$7$?!#$"$j$,$H$&$4$6$$$^$9!#e(B
e$B$G$9$,$d$O$j!"Kh2se(B .tap(&:p) e$B$H=q$/$h$je(B .p
e$B$G:[email protected]}$,[email protected]$H;W$$$^$9!#e(B

e$BB>$G$b$J$$e(B p e$B%a%=%C%I$G$"$k$H$$$&$N$,[email protected]$H;W$C$F$$$^$9!#e(B
e$B$3$l$,e(B p e$B$G$J$/e(B print [email protected]$C$?$i$4$M$F$$$^$;$se(B
(e$B>Pe(B)

e$B1sF#$H?=$7$^$9!#e(B

e$BH>G/0J>e7P$C$F$7$^$$$^$7$?$,!"$3$NDs0Fe(B (ruby-dev:29736)
[email protected]$5$l$?e(B
e$B$N$G$7$g$&$+!#e(B
e$B$3$l$,$"$k$H%G%P%C%0$,$h$j0lAX3Z$K$J$k$N$G!"$48!F$$/[email protected]$5$l$P9,$$$G$9!#e(B

e$B0l1~$3$NJQ99$K$h$k1F6A$r$O$+$k$?$a!"%Q%C%A$r$"$F$?e(B ruby 1.8 (svn)
e$B$Ge(B
rails 1.2 (svn) e$B$N0J2<$N%Q%C%1!<%8$re(B rake test
e$B$7$F8+$^$7$?$,!"e(B
e$B$9$Y$F%Q%9$7$^$7$?e(B (i686-linux, Debian etch) e$B!#e(B

actionmailer, actionpack, actionwebservice, activesupport

activerecord e$B$O4D6-9=C[$,[email protected]$C$?$N$Ge(B rake test_mysql e$B$7$+e(B
e$B;n$;$F$$$^$;$s$,!"$3$l$O%Q%9$7$^$7$?!#e(B

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

e$B$(!<$H!"$H$j$"$($:!"0z?t$r$=$N$^$^La$jCM$K$9$kItJ,$O<h$j9~$`e(B
e$B$3$H$K$7$^$7$?!#e(B

HEAD e$B$G3NG$7$^$7$?!#$"$j$,$H$&$4$6$$$^$9!#e(B
e$B$3$l$G$^$?e(B Ruby e$B$+$iN%$l$i$l$J$$M}M3$,A}$($^$7$?!#e(B

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

In message Re: [ruby-dev:30873] Re: [e$BDs0Fe(B] Kernel#p
e$B$r$b$C$HJXMx$Ke(B
on Sat, 2 Jun 2007 20:27:30 +0900, Yusuke ENDOH [email protected]
writes:

|e$BH>G/0J>e7P$C$F$7$^$$$^$7$?$,!"$3$NDs0Fe(B (ruby-dev:29736) [email protected]$5$l$?e(B
|e$B$N$G$7$g$&$+!#e(B
|e$B$3$l$,$"$k$H%G%P%C%0$,$h$j0lAX3Z$K$J$k$N$G!"$48!F$$/[email protected]$5$l$P9,$$$G$9!#e(B

e$B$(!<$H!"$H$j$"$($:!"0z?t$r$=$N$^$^La$jCM$K$9$kItJ,$O<h$j9~$`e(B
e$B$3$H$K$7$^$7$?!#e(Bobj.p e$B$Ge(B p obj
e$B$N$h$&$KF0:n$9$kItJ,$OJ]N1$Ge(B
e$B$9!#e(B

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

In message Re: [ruby-dev:30902] Re: [e$BDs0Fe(B] Kernel#p
e$B$r$b$C$HJXMx$Ke(B
on Thu, 7 Jun 2007 00:09:35 +0900, Yusuke ENDOH [email protected]
writes:

|> e$B$(!<$H!"$H$j$"$($:!0z?t$r$=$N$^$^La$jCM$K$9$kItJ,$O<h$j9~$`e(B
|> e$B$3$H$K$7$^$7$?!#e(B
|
|HEAD e$B$G3NG$7$^$7$?!#$$j$,$H$&$4$6$$$^$9!#e(B
|e$B$3$l$G$^$?e(B Ruby e$B$+$iN%$l$i$l$J$$M}M3$,A}$($^$7$?!#e(B

e$B$G!e(Bself.pe$B$G<+J,<+?H$r=PNO$9$kJ}$G$9$,!$J$s$+$$$m$$$m$HG<[email protected](B
e$B$G$-$J$$$H$3$m$,$"$j$^$9!#e(B

p

e$B$O$I$&F0$/$N$+$H$+e(B(p selfe$B$HF1$8!"$OJQ$J5$$,e(B)

self.p(obj)

e$B$O$I$&$J$N$+$H$+!#$=$NJU$,2r7he(B(e$BG<[email protected](B)e$B$G$-$?$i!"$H$$$&$3$H$G!#e(B

e$B8eF#$H$$$$$^$9!#e(B

e$B$?$H$($Pe(B
P = Struct.new(:p, :sd)
x = P.new(0.1, 0.01)
p x.p
e$B$H$+e(B
class A
attr_accessor :p, :v
end
y = A.new
y.p = 0.05
e$B$N$h$&$K!";d$O!e(Bpe$B$H$$$&%a%=%C%I$r<+J,$GDj5A$7$F;H$&$3$H$,$$j$^$9!#e(B
Kernele$B$G:G=i$+$iDj5A$5$l$k$H=EJ#Dj5A$K$J$C$F$d$d$3$7$=$&$J$N$G!"e(B
e$B;d$O!Ve(Bself.pe$B$G<+J,<+?H$r=PNO$9$kJ}!W$OF3F~H?BP$G$9!#e(B

On Thu, 7 Jun 2007 00:32:33 +0900

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

e$B$G!e(Bself.pe$B$G<+J,<+?H$r=PNO$9$kJ}$G$9$,!$J$s$+$$$m$$$m$HG<[email protected](B
e$B$G$-$J$$$H$3$m$,$"$j$^$9!#e(B

e$B$=$&$$$&6Z$,DL$C$F$$$k$N$OB?$/$N>[email protected]$H;W$$$^$9$,!"e(B
p e$B$N>l9g$K8B$C$F$O![email protected]$19M$($F;H$$$d$9$5$rM%@h$G$be(B
e$B$$$$$s$8$c$J$$$+$J!$H$$$&5$;}$A$G$7$?!#e(B

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