|
|||
Previous < |
Contents ^
|
Next >
|
irb
is run from the command line.
irb [ irb-options ] [ ruby_script ] [ options ] |
irb command-line options
|
~/.irbrc
, .irbrc
, irb.rc
,
_irbrc
, and $irbrc
.
Within the initialization file you may run any arbitrary Ruby code.
You can also set any of the configuration values that correspond to
command-line arguments as shown in Table B.2 on page 518.
irb configuration values
|
IRB.conf[:IRB_RC]
to a Proc
object. This proc will be
invoked whenever the irb context is changed, and will receive that new
context as a parameter. You can use this facility to change the
configuration dynamically based on the context.
exit, quit, irb_exit
cb
to change bindings (see below), exits from
this binding mode.
conf, irb_context
conf
.
conf.back_trace_limit n
conf.debug_level = N
conf.ignore_eof = true/false
conf.ignore_sigint= true/false
conf.inf_ruby_mode = true/false
true
, changes the prompt and disables readline support,
allowing irb to work with
inf-ruby-mode
. [inf-ruby-mode
allows Emacs
users to interact with
Ruby while editing programs. See the file inf_ruby.el
in the
misc
directory of the distribution for more details.] The
default value is false.
conf.inspect_mode = true/false/nil
true
|
Display inspect (default). |
false
|
Display to_s. |
nil
|
Inspect mode in non-math mode, non-inspect mode in math mode. |
conf.irb_level
cb
).
conf.math_mode
conf.use_loader = true/false
load
/require
.
conf.prompt_c
conf.prompt_i
conf.prompt_s
conf.rc = true/false
~/.irbrc
.
conf.use_prompt = true/false
conf.use_readline = true/false/nil
true
|
Use Readline. |
false
|
Do not use Readline. |
nil
|
Use Readline except for inf-ruby-mode (default). |
conf.verbose=true/false
cb, irb_change_binding [
obj
]
irb [obj]
jobs, irb_jobs
fg n, irb_fg n
irb subsession number |
thread id |
irb object |
self (the obj that launched a particular subsession) |
kill n, irb_kill n
irb_fg
.
IRB.conf[:PROMPT] |
.irbrc
file):
IRB.conf[:PROMPT][:MY_PROMPT] = { # name of prompt mode :PROMPT_I => "...", # normal prompt :PROMPT_S => "...", # prompt for continuing strings :PROMPT_C => "...", # prompt for continuing statement :RETURN => " ==>%s\n" # format to return value } |
% irb --prompt my-prompt
Or set the following configuration value:
IRB.conf[:PROMPT_MODE] = :MY_PROMPT |
PROMPT_I
, PROMPT_S
, and PROMPT_C
specify the format for each of the prompt strings. Within the prompt
format, the following flags are available and will expand to the
given text:
Flag | Description | |||||||
%N
|
Current command. | |||||||
%m
|
to_s of the main object (self). |
|||||||
%M
|
inspect of the main object (self). |
|||||||
%l
|
Delimiter type. In strings that are continued across a line break,
%l will display the type of delimiter used to begin the
string, so you'll know how to end it. The delimiter will be
one of " , ' , / , ] , or ` . |
|||||||
%ni
|
Indent level. The optional number n is used as a width
specification to printf, as printf("%nd") . |
|||||||
%nn
|
Current line number (n used as with the indent level). | |||||||
%%
|
A literal percent sign. | |||||||
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" } |
eval "a = 0" a |
prog.rb:2: undefined local variable or method `a' |
irb(main):001:0> eval "a = 0" 0 irb(main):002:0> a 0In irb, the assignment was executed before the second line was encountered, so ``a'' is correctly identified as a local variable. If you need to match the Ruby behavior more closely, you can place these statements within a
begin
/end
pair.
irb(main):001:0> begin irb(main):002:1* eval "a = 0" irb(main):003:1> a irb(main):004:1> end NameError: undefined local variable or method `a' (irb):3:in `irb_binding'
rtags
is a command used to create a TAGS
file for use with
either the emacs or vi editor.
rtags [ -vi ] [ files ]... |
TAGS
file suitable for emacs (see
etags.el). The -vi
option makes a TAGS file for use with vi.
rtags needs to be installed in the same manner as irb (that is, you
need to install irb in the library path and make a link from
irb/rtags.rb
to bin/rtags
).
require "irb/xmp" xmp <<END artist = "Doc Severinsen" artist END |
[pwd:/tc/work/ruby/ProgrammingRuby/latex] artist = "Doc Severinsen" ==>"Doc Severinsen" artist ==>"Doc Severinsen" |
require "irb/xmp" x = XMP.new x.puts <<END artist = "Louis Prima" END x.puts <<END artist END |
[pwd:/tc/work/ruby/ProgrammingRuby/latex] artist = "Louis Prima" ==>"Louis Prima" artist ==>"Louis Prima" |
xmp code_string, abinding XMP.new(abinding) |
IRB::Frame
class represents the interpreter's stack and allows
easy access to the Binding
environment in effect at different
stack levels.
IRB::Frame.top(n = 0)
|
Returns a Binding
for the nth context from the top. The 0th context is
topmost,
most recent frame. |
|||||||
IRB::Frame.bottom(n = 0)
|
Returns a Binding for the
nth context from the bottom. The 0th context is the
bottommost, initial frame. |
|||||||
IRB::Frame.sender
|
Returns the object (the sender) that invoked the current method. | |||||||
require 'irb/frame' def outie b = IRB::Frame.top(1) eval "p my_local", b end def innie my_local = 102.7 outie end innie |
102.7 |
Previous < |
Contents ^
|
Next >
|