forked from mruby/mruby
-
Notifications
You must be signed in to change notification settings - Fork 4
Special Variables
Tomoyuki Sahara edited this page Jun 25, 2014
·
7 revisions
MRI's Special Variables:
-
list of all special variables
-
$! $ " $$$& $ '$* $ +$, $ /$; $ :$-W $ -a$DEBUG $ -i$-l $ -p$VERBOSE $ -v$-w $ . $0$1 $ <$= $ >$? $ @ $FILENAME$SAFE $
$_$ ` $stderr$stdin $ ~
-
-
Grouping by scope / accessibility
scope | access | |
---|---|---|
global | read/write |
|
global | read-only | $$ |
thread | read/write | $@ $SAFE |
thread | read-only |
|
local/thread | read/write | $_ |
local/thread | read-only |
|
( |
- Grouping by Module
module | variables |
---|---|
(Core) |
|
IO |
|
Regexp |
|
Process | $$ |
String | $; |
require |
|
bin/mruby |
|
(Note: $; is in both String and Regexp. $0 is in both Process and bin/mruby) |
-
aliases:
- $" = $LOADED_FEATURES
-
$/ = $ -O -
$; = $ -F - $: =
$LOAD_PATH = $ -I -
$DEBUG = $ -d - $0 = $PROGRAM_NAME
- $> = $stdout
-
Implementation
- $! : mrb_obj_value(mrb->exc)
- $$ : return Process.pid
-
$& : $ ~[0] -
$' : $ ~.post_match - $* : return ARGV
-
$+ : $ ~.[-1] - $0 : mrb_str_new...(..., ARGV[0] or getprogname())
-
$1 : $ ~[1] - $< : ...?
- $? : can be a module variable of Process
- $@ : ...?
- $_ : set by IO#gets, IO#readline, Kernel.gets and Kernel.readline
-
$` : $ ~.pre_match - $~ : set by Regexp....
- (same as a global variable) :
$" $ ,$/ $ ;$: $ . $> $stderr $stdin - (won't support but implementation should be trivial):
$-W $ -a$DEBUG $ -i$-l $ -p$VERBOSE $ -v $-w $FILENAME$SAFE $ \
- stored in
(struct iv_tbl *)mrb->globals
- Special Variables in MRI 2.1.0 (in Japanese): http://docs.ruby-lang.org/ja/2.1.0/class/Kernel.html#V_--21