Skip to content

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 $" $, $/ $: $DEBUG $-i $VERBOSE $-v $-w $. $0 $> $\ $stderr $stdin
global read-only $$ $* $-W $-a $-l $-p $< $FILENAME
thread read/write $@ $SAFE
thread read-only $! $?
local/thread read/write $_
local/thread read-only $& $' $+ $1 $` $~
($KCODE and $= are deprecated)
  • Grouping by Module
module variables
(Core) $! $, $DEBUG $VERBOSE $@ $SAFE $\
IO $/ $. $> $_ $stderr $stdin
Regexp $& $' $+ $; $1 $` $~
Process $$ $0 $?
String $;
require $" $:
bin/mruby $* $-a $-i $-l $-p $-v $-w $0 $< $FILENAME
(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 $\

Global Variables

  • stored in (struct iv_tbl *)mrb->globals

Reference

Clone this wiki locally