1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/doc/irb/irb.rd.jp
knu f8ab487e4d Initial revision
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1337 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2001-04-30 17:38:21 +00:00

13 KiB

irb -- interactive ruby
$Release Version: 0.6 $
$Revision$
$Date$
by Keiju ISHITSUKA(keiju@ishitsuka.com)
==begin
= irb$B$H$O?
 
irb$B$Ointeractive ruby$B$NN,$G$9. ruby$B$N<0$rI8=`F~NO$+$i4JC1$KF~NO/$B<B9T$9
$B$k$?$a$N%D!<%k$G$9.
 
= $B5/F0
 
% ruby -r irb -e0
% irb
 
$B$N$$$:$l$+$G9T$J$$$^$9. $BA0<T$N>l9girb$B$X$N%*%W%7%g%s;XDj$O, $B0J2<$N$h$&$K
$B$J$j$^$9.
 
% ruby -r irb -e0 -- -v
 
= $B;H$$J}
 
irb$B$N;H$$J}$O, Ruby$B$5$(CN$C$F$$$l$P$$$?$C$F4JC1$G$9. $B4pK\E*$K$O irb $B$H
$B$$$&%3%^%s%I$r<B9T$9$k$@$1$G$9. irb$B$r<B9T$9$k$H, $B0J2<$N$h$&$J%W%m%s%W
$B%H$,I=$l$F$-$^$9. $B8e$O, ruby$B$N<0$rF~$l$F2<$5$$. $B<0$,407k$7$?;~E@$G<B9T
$B$5$l$^$9.
 
dim% irb
irb(main):001:0> 1+2
3
irb(main):002:0> class Foo
irb(main):003:1> def foo
irb(main):004:2> print 1
irb(main):005:2> end
irb(main):006:1> end
nil
irb(main):007:0>
 
$B$^$?, irb$B$OReadline$B%b%8%e!<%k$K$bBP1~$7$F$$$^$9. Readline$B%b%8%e!<%k$,
$B%$%s%9%H!<%k$5$l$F$$$k;~$K$O, $B$=$l$r;H$&$N$,I8=`$NF0:n$K$J$j$^$9.
 
= $B%3%^%s%I%*%W%7%g%s
 
irb.rb [options] file_name opts
options:
-f ~/.irbrc $B$rFI$_9~$^$J$$.
-m bc$B%b!<%I($BJ,?t, $B9TNs$N7W;;$,$G$-$k)
-d $DEBUG $B$rtrue$B$K$9$k(ruby -d $B$HF1$8)
-r load-module ruby -r $B$HF1$8.
--inspect $B7k2L=PNO$Kinspect$B$rMQ$$$k(bc$B%b!<%I0J30$O%G%U%)%k%H).
--noinspect $B7k2L=PNO$Kinspect$B$rMQ$$$J$$.
--readline readline$B%i%$%V%i%j$rMxMQ$9$k.
--noreadline readline$B%i%$%V%i%j$rMxMQ$7$J$$. $B%G%U%)%k%H$NF0:n$O,
inf-reuby-mode$B0J30$Greadline$B%i%$%V%i%j$rMxMQ$7$h$&
$B$H$9$k.
--prompt prompt-mode
--prompt-mode prompt-mode
$B%W%m%s%W%H%b!<%I$r@ZBX$($^$9. $B8=:_Dj5A$5$l$F$$$k%W
$B%m%s%W%H%b!<%I$O, defalut, simple, xmp, inf-ruby$B$,
$BMQ0U$5$l$F$$$^$9. $B%G%U%)%k%H$Odefault$B%W%m%s%W%H%b!<
$B%I$K$J$C$F$$$^$9.
 
--inf-ruby-mode emacs$B$Ninf-ruby-mode$BMQ$N%W%m%s%W%HI=<($r9T$J$&. $BFC
$B$K;XDj$,$J$$8B$j, readline$B%i%$%V%i%j$O;H$o$J$/$J$k.
--simple-prompt
$BHs>o$K%7%s%W%k$J%W%m%s%W%H$rMQ$$$k%b!<%I$G$9.
--noprompt $B%W%m%s%W%HI=<($r9T$J$o$J$$.
--tracer $B%3%^%s%I<B9T;~$K%H%l!<%9$r9T$J$&.
--back-trace-limit n
$B%P%C%/%H%l!<%9I=<($r%P%C%/%H%l!<%9$NF,$+$i n, $B8e$m
$B$+$in$B$@$19T$J$&. $B%G%U%)%k%H$O16
--irb_debug n irb$B$N%G%P%C%0%G%P%C%0%l%Y%k$rn$B$K@_Dj$9$k($BMxMQ$7$J
$B$$J}$,L5Fq$G$7$g$&).
-v, --version irb$B$N%P!<%8%g%s$rI=<($9$k
 
= $B%3%s%U%#%.%e%l!<%7%g%s
 
irb$B5/F0;~$K``~/.irbrc''$B$rFI$_9~$_$^$9. $B$b$7B8:_$7$J$$>l9g$O,
``.irbrc'', ``irb.rc'', ``_irbrc'', ``$irbrc''$B$N=g$Kload$B$r;n$_$^$9.
 
$B%*%W%7%g%s$r@_Dj$9$kBe$o$j$K, $B0J2<$N%3%^%s%I$G$b%G%U%)%k%H$NF0:n$r@_Dj
$B$G$-$^$9.
 
IRB.conf[:IRB_NAME]="irb"
IRB.conf[:MATH_MODE]=false
IRB.conf[:USE_TRACER]=false
IRB.conf[:USE_LOADER]=false
IRB.conf[:IGNORE_SIGINT]=true
IRB.conf[:IGNORE_EOF]=false
IRB.conf[:INSPECT_MODE]=nil
IRB.conf[:IRB_RC] = nil
IRB.conf[:BACK_TRACE_LIMIT]=16
IRB.conf[:USE_LOADER] = false
IRB.conf[:USE_READLINE] = nil
IRB.conf[:USE_TRACER] = false
IRB.conf[:IGNORE_SIGINT] = true
IRB.conf[:IGNORE_EOF] = false
IRB.conf[:PROMPT_MODE] = :DEFALUT
IRB.conf[:PROMPT] = {...}
IRB.conf[:DEBUG_LEVEL]=0
IRB.conf[:VERBOSE]=true
 
== $B%W%m%s%W%H$N@_Dj
 
$B%W%m%s%W%H$r%+%9%?%^%$%:$7$?$$;~$K$O,
 
IRB.conf[:PROMPT]
 
$B$rMQ$$$^$9. $BNc$($P, .irbrc$B$NCf$G2<$N$h$&$J<0$r5-=R$7$^$9:
 
IRB.conf[:PROMPT][:MY_PROMPT] = { # $B%W%m%s%W%H%b!<%I$NL>A0
:PROMPT_I => nil, # $BDL>o$N%W%m%s%W%H
:PROMPT_S => nil, # $BJ8;zNs$J$I$N7QB39T$N%W%m%s%W%H
:PROMPT_C => nil, # $B<0$,7QB3$7$F$$$k;~$N%W%m%s%W%H
:RETURN => " ==>%s\n" # $B%j%?!<%s;~$N%W%m%s%W%H
}
 
$B%W%m%s%W%H%b!<%I$r;XDj$7$?$$;~$K$O,
 
irb --prompt my-prompt
 
$B$G$=$N%W%m%s%W%H%b!<%I$G5/F0$5$l$^$9. $B$^$?$O, .irbrc$B$K2<<0$r5-=R$7$F$b
OK$B$G$9.
 
IRB.conf[:PROMPT_MODE] = :MY_PROMPT
 
PROMPT_I, PROMPT_S, PROMPT_C$B$O, $B%U%)!<%^%C%H$r;XDj$7$^$9.
 
%N $B5/F0$7$F$$$k%3%^%s%IL>$,=PNO$5$l$k.
%m main$B%*%V%8%'%/%H(self)$B$,to_s$B$G=PNO$5$l$k.
%M main$B%*%V%8%'%/%H(self)$B$,inspect$B$5$l$F=PNO$5$l$k.
%l $BJ8;zNsCf$N%?%$%W$rI=$9(", ', /, ], `]'$B$O%w$B$NCf$N;~)
%NNi $B%$%s%G%s%H$N%l%Y%k$rI=$9. NN$B$O?t;z$,F~$jprintf$B$N%NNd$B$HF1$8. $B>J
$BN,2DG=
%NNn $B9THV9f$rI=$7$^$9.
%% %
 
$BNc$($P, $B%G%U%)%k%H$N%W%m%s%W%H%b!<%I$O:
 
IRB.conf[:PROMPT_MODE][:DEFAULT] = {
:PROMPT_I => "%N(%m):%03n:%i> ",
:PROMPT_S => "%N(%m):%03n:%i%l ",
:PROMPT_C => "%N(%m):%03n:%i* ",
:RETURN => "%s\n"
}
 
$B$H$J$C$F$$$^$9.
 
RETURN$B$O, $B8=:_$N$H$3$mprintf$B7A<0$G$9. $B>-Mh;EMM$,JQ$o$k$+$bCN$l$^$;$s.
 
== $B%5%Virb$B$N@_Dj
 
$B%3%^%s%I%i%$%s%*%W%7%g%s$*$h$SIRB.conf$B$O($B%5%V)irb$B5/F0;~$N%G%U%)%k%H$N
$B@_Dj$r7h$a$k$b$N$G, `5. $B%3%^%s%I'$B$K$"$kconf$B$G8DJL$N($B%5%V)irb$B$N@_Dj$,$G
$B$-$k$h$&$K$J$C$F$$$^$9.
 
IRB.conf[:IRB_RC]$B$Kproc$B$,@_Dj$5$l$F$$$k$H, $B%5%Virb$B$r5/F0$9$k;~$K$=$N
proc$B$rirb$B$N%3%s%F%-%9%H$r0z?t$H$7$F8F$S=P$7$^$9. $B$3$l$K$h$C$F8DJL$N%5
$B%Virb$B$4$H$K@_Dj$rJQ$($k$3$H$,$G$-$k$h$&$K$J$j$^$9.
 
 
= $B%3%^%s%I
 
irb$B3HD%%3%^%s%I$O, $B4JC1$JL>A0$HF,$K`irb_'$B$r$D$1$?L>A0$HN>J}Dj5A$5$l$F
$B$$$^$9. $B$3$l$O, $B4JC1$JL>A0$,override$B$5$l$?;~$N$?$a$G$9.
 
--- exit, quit, irb_exit
$B=*N;$9$k.
$B%5%Virb$B$N>l9g, $B$=$N%5%Virb$B$r=*N;$9$k.
cb$B$7$F$$$k>l9g, $B$=$N%P%$%s%G%#%s%0$N%b!<%I$r=*N;$9$k.
 
--- conf, irb_context
irb$B$N8=:_$N@_Dj$rI=<($9$k. $B@_Dj$NJQ99$O, conf$B$K%a%C%;!<%8$rAw$k$3
$B$H$K$h$C$F9T$J$($k.
 
--- conf.back_trace_limit
$B%P%C%/%H%l!<%9I=<($r%P%C%/%H%l!<%9$NF,$+$in, $B8e$m$+$in$B$@$19T$J$&.
$B%G%U%)%k%H$O16
 
--- conf.debug_level = N
irb$BMQ$N%G%P%C%0%l%Y%k$N@_Dj
 
--- conf.ignore_eof = true/false
^D$B$,F~NO$5$l$?;~$NF0:n$r@_Dj$9$k. true$B$N;~$O^D$B$rL5;k$9$k, false$B$N
$B;~$Oirb$B$r=*N;$9$k.
 
--- conf.ignore_sigint= true/false
^C$B$,F~NO$5$l$?;~$NF0:n$r@_Dj$9$k. false$B;~$O, irb$B$r=*N;$9$k. true$B$N
$B;~$NF0:n$O0J2<$N$h$&$K$J$k:
$BF~NOCf: $B$3$l$^$GF~NO$7$?$b$N$r%-%c%s%;%k$7%H%C%W%l%Y%k$KLa$k.
$B<B9TCf: $B<B9T$rCf;_$9$k.
 
--- conf.inf_ruby_mode = true/false
inf-ruby-mode$BMQ$N%W%m%s%W%HI=<($r9T$J$&. $B%G%U%)%k%H$Ofalse.
 
--- conf.inspect_mode = true/false/nil
$B%$%s%9%Z%/%H%b!<%I$r@_Dj$9$k.
true: $B%$%s%9%Z%/%H$7$FI=<($9$k.
false: $BDL>o$Nprint$B$GI=<($9$k.
nil: $BDL>o%b!<%I$G$"$l$P, inspect mode$B$H$J$j, math$B%b!<%I$N;~$O, non
inspect mode$B$H$J$k.
 
--- conf.irb_level
$B;2>H$N$_. irb$B$,2?CJcb$B$7$F$$$k$+?
 
--- conf.math_mode
$B;2>H$N$_. bc$B%b!<%I($BJ,?t, $B9TNs$N7W;;$,$G$-$^$9)$B$+$I$&$+?
 
--- conf.use_loader = true/false
load/require$B;~$Kirb$B$Nfile$BFI$_9~$_5!G=$rMQ$$$k%b!<%I$N%9%$%C%A($B%G%U%)
$B%k%H$OMQ$$$J$$). $B$3$N%b!<%I$OIRB$BA4BN$KH?1G$5$l$k.
 
--- conf.prompt_c
if$B$ND>8e$J$I, $B9T$,7QB3$7$F$$$k;~$N%W%m%s%W%H.
 
--- conf.prompt_i
$BDL>o$N%W%m%s%W%H.
 
--- conf.prompt_s
$BJ8;zNsCf$J$I$rI=$9%W%m%s%W%H.
 
--- conf.rc
~/.irbrc$B$rFI$_9~$s$@$+$I$&$+?
 
--- conf.use_prompt = true/false
$B%W%m%s%W%HI=<($9$k$+$I$&$+? $B%G%U%)%k%H$G$O%W%m%s%W%H$rI=<($9$k.
 
--- conf.use_readline = true/false/nil
readline$B$r;H$&$+$I$&$+?
true: readline$B$r;H$&.
false: readline$B$r;H$o$J$$.
nil: ($B%G%U%)%k%H)inf-reuby-mode$B0J30$Greadline$B%i%$%V%i%j$rMxMQ$7$h
$B$&$H$9$k.
 
--- conf.verbose=T/F
irb$B$+$i$$$m$$$m$J%a%C%;!<%8$r=PNO$9$k$+?
 
--- cb, irb_change_binding [obj]
$B%m!<%+%kJQ?t$N%9%3!<%W$,0c$&?7$?$Jbinding$B$K0\$k. obj$B$,;XDj$5$l$?
$B;~$O, $B$=$Nobj$B$rself$B$H$9$k.
 
--- irb [obj]
$B%5%Virb$B$rN)$A$"$2$k. obj$B$,;XDj$5$l$?;~$O, $B$=$Nobj$B$rself$B$H$9$k.
 
--- jobs, irb_jobs
$B%5%Virb$B$N%j%9%H
 
--- fg n, irb_fg n
$B;XDj$7$?%5%Virb$B$K%9%$%C%A$9$k. n$B$O, $B<!$N$b$N$r;XDj$9$k.
 
irb$BHV9f
$B%9%l%C%I
irb$B%*%V%8%'%/%H
self(irb obj$B$G5/F0$7$?;~$Nobj)
 
--- kill n, irb_kill n
$B%5%Virb$B$rkill$B$9$k. n$B$Ofg$B$HF1$8.
 
 
= $B%7%9%F%`JQ?t
 
_ $BA0$N7W;;$N<B9T7k2L$r3P$($F$$$k($B%m!<%+%kJQ?t).
 
= $B;HMQNc
 
$B0J2<$N$h$&$J46$8$G$9.
 
dim% ruby irb.rb
irb(main):001:0> irb # $B%5%Virb$B$NN)$A$"$2
irb#1(main):001:0> jobs # $B%5%Virb$B$N%j%9%H
#0->irb on main (#<Thread:0x400fb7e4> : stop)
#1->irb#1 on main (#<Thread:0x40125d64> : running)
nil
irb#1(main):002:0> fg 0 # job$B$N%9%$%C%A
nil
irb(main):002:0> class Foo;end
nil
irb(main):003:0> irb Foo # Foo$B$r%3%s%F%-%9%H$7$Firb
# $BN)$A$"$2
irb#2(Foo):001:0> def foo # Foo#foo$B$NDj5A
irb#2(Foo):002:1> print 1
irb#2(Foo):003:1> end
nil
irb#2(Foo):004:0> fg 0 # job$B$r%9%$%C%A
nil
irb(main):004:0> jobs # job$B$N%j%9%H
#0->irb on main (#<Thread:0x400fb7e4> : running)
#1->irb#1 on main (#<Thread:0x40125d64> : stop)
#2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
nil
irb(main):005:0> Foo.instance_methods # Foo#foo$B$,$A$c$s$HDj5A$5
# $B$l$F$$$k
["foo"]
irb(main):006:0> fg 2 # job$B$r%9%$%C%A
nil
irb#2(Foo):005:0> def bar # Foo#bar$B$rDj5A
irb#2(Foo):006:1> print "bar"
irb#2(Foo):007:1> end
nil
irb#2(Foo):010:0> Foo.instance_methods
["bar", "foo"]
irb#2(Foo):011:0> fg 0
nil
irb(main):007:0> f = Foo.new
#<Foo:0x4010af3c>
irb(main):008:0> irb f # Foo$B$N%$%s%9%?%s%9$Girb$B$r
# $BN)$A$"$2$k.
irb#3(#<Foo:0x4010af3c>):001:0> jobs
#0->irb on main (#<Thread:0x400fb7e4> : stop)
#1->irb#1 on main (#<Thread:0x40125d64> : stop)
#2->irb#2 on Foo (#<Thread:0x4011d54c> : stop)
#3->irb#3 on #<Foo:0x4010af3c> (#<Thread:0x4010a1e0> : running)
nil
irb#3(#<Foo:0x4010af3c>):002:0> foo # f.foo$B$N<B9T
nil
irb#3(#<Foo:0x4010af3c>):003:0> bar # f.bar$B$N<B9T
barnil
irb#3(#<Foo:0x4010af3c>):004:0> kill 1, 2, 3# job$B$Nkill
nil
irb(main):009:0> jobs
#0->irb on main (#<Thread:0x400fb7e4> : running)
nil
irb(main):010:0> exit # $B=*N;
dim%
 
= $B;HMQ>e$N@)8B
 
irb$B$O, $BI>2A$G$-$k;~E@($B<0$,JD$8$?;~E@)$B$G$NC`<!<B9T$r9T$J$$$^$9. $B$7$?$,$C
$B$F, ruby$B$rD>@\;H$C$?;~$H, $B<c430[$J$kF0:n$r9T$J$&>l9g$,$"$j$^$9.
 
$B8=:_L@$i$+$K$J$C$F$$$kLdBjE@$r@bL@$7$^$9.
 
== $B%m!<%+%kJQ?t$N@k8@
 
ruby$B$G$O, $B0J2<$N%W%m%0%i%`$O%(%i!<$K$J$j$^$9.
 
eval "foo = 0"
foo
--
-:2: undefined local variable or method `foo' for #<Object:0x40283118> (NameError)
---
NameError
 
$B$H$3$m$,, irb$B$rMQ$$$k$H
 
>> eval "foo = 0"
=> 0
>> foo
=> 0
 
$B$H$J$j, $B%(%i!<$r5/$3$7$^$;$s. $B$3$l$O, ruby$B$,:G=i$K%9%/%j%W%HA4BN$r%3%s
$B%Q%$%k$7$F%m!<%+%kJQ?t$r7hDj$9$k$+$i$G$9. $B$=$l$KBP$7, irb$B$O<B9T2DG=$K
$B$J$k($B<0$,JD$8$k)$B$H<+F0E*$KI>2A$7$F$$$k$+$i$G$9. $B>e5-$NNc$G$O,
 
evel "foo = 0"
 
$B$r9T$J$C$?;~E@$GI>2A$r9T$J$$, $B$=$N;~E@$GJQ?t$,Dj5A$5$l$k$?$a, $B<!<0$G
$BJQ?tfoo$B$ODj5A$5$l$F$$$k$+$i$G$9.
 
$B$3$N$h$&$Jruby$B$Hirb$B$NF0:n$N0c$$$r2r7h$7$?$$>l9g$O, begin...end$B$G3g$C$F
$B%P%C%AE*$K<B9T$7$F2<$5$$:
 
>> begin
?> eval "foo = 0"
>> foo
>> end
NameError: undefined local variable or method `foo' for #<Object:0x4013d0f0>
(irb):3
(irb_local_binding):1:in `eval'
 
== $B%R%"%I%-%e%a%s%H
 
$B8=:_$N$H$3$m%R%"%I%-%e%a%s%H$N<BAu$OIT40A4$G$9.
 
== $B%7%s%\%k
 
$B%7%s%\%k$G$"$k$+$I$&$+$NH=CG$r4V0c$($k$3$H$,$"$j$^$9. $B6qBNE*$K$O<0$,40N;
$B$7$F$$$k$N$K7QB39T$H8+$J$9$3$H$,$"$j$^$9.
 
==end
 
% Begin Emacs Environment
% Local Variables:
% mode: text
% comment-column: 0
% comment-start: "%"
% comment-end: "\n"
% End:
%