From: Julio Olivera Date: 2013-04-24T13:09:21+09:00 Subject: Re: what is the $- magic global? --047d7b86d55c5df92204db13772b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable If you try it on http://repl.it/, $- immediately returns nil. Perhaps on irb the interpreter is waiting for more input? I can't test it right now, but what happens if you write something like the following? > $-x =3D 42 > $- > x Julio @_joliv On Wed, Apr 24, 2013 at 1:00 AM, tamouse mailing lists < tamouse.lists@gmail.com> wrote: > On Tue, Apr 23, 2013 at 9:21 PM, Matthew Kerwin > wrote: > > Also: I'm aware of bash's $- options description, but that doesn't seem > > relevant in this case; bash's $- is a simple string, and doesn't have > > any magic attached. > > > > I know that perl and ruby both have a similarly-defined $+ magic > > variable. Perl also has a $- ("The number of lines left on the page of > > the currently selected output channel.") but I doubt there's a > > correlation with ruby's, because perl's is a simple integer, and is > > related to $~ and $=3D which are completely different between the two > > languages. > > > > I've also encountered perl's @-/@+ match offsets, but can't see how > > they'd be relevant. > > Hummm... I'm flummoxed as well. I just went through the newest > Programming Ruby book (beta 2) and cannot find anything referencing > $-. It lists these: > > $-0 =E2=86=92 String Synonym for $/ > $-F =E2=86=92 String Synonym for $; > $-a =E2=86=92 Object True if the -a option is specified on the command li= ne > $-d =E2=86=92 Object Synonym for $DEBUG. > $-i =E2=86=92 String If in-place edit mode is enabled (perhaps using the = -i > command-line option), $-i holds the extension used when creating the > backup file. > $-I =E2=86=92 Array Synonym for $: > $-l =E2=86=92 Object Set to true if the -l option (which enables line-end > processing) is present on the command line. > $-p =E2=86=92 Object Set to true if the -p option (which puts an implicit > while gets...end loop around your program) is present on the command > line. > $-v =E2=86=92 Object Synonym for $VERBOSE. > $-w =E2=86=92 Object Synonym for $VERBOSE. > $-W =E2=86=92 Object Return the value set by the -W command-line option. > > and this: > > "a global variable name can be formed using $- followed by a single > letter or underscore" [p 318 in PDF] > > but no bare $- variable.... > > --047d7b86d55c5df92204db13772b Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
If you try it on=C2=A0http://r= epl.it/, $- immediately returns nil. Perhaps on irb the interpreter is = waiting for more input? I can't test it right now, but what happens if = you write something like the following?

> $-x =3D 42
> $-
> x

Julio


On Wed, Apr 24, 2013 at 1:00 AM, tamouse= mailing lists <tamouse.lists@gmail.com> wrote:
On Tue, Apr 23, 2013 at 9:21 PM, Matthew Kerwin <lists@ruby-forum.com> wrote:
> Also: I'm aware of bash's $- options description, but that doe= sn't seem
> relevant in this case; bash's $- is a simple string, and doesn'= ;t have
> any magic attached.
>
> I know that perl and ruby both have a similarly-defined $+ magic
> variable. =C2=A0Perl also has a $- ("The number of lines left on = the page of
> the currently selected output channel.") but I doubt there's = a
> correlation with ruby's, because perl's is a simple integer, a= nd is
> related to $~ and $=3D which are completely different between the two<= br> > languages.
>
> I've also encountered perl's @-/@+ match offsets, but can'= t see how
> they'd be relevant.

Hummm... I'm flummoxed as well. I just went through the newest Programming Ruby book (beta 2) and cannot find anything referencing
$-. It lists these:

$-0 =E2=86=92 String Synonym for $/
$-F =E2=86=92 String Synonym for $;
$-a =E2=86=92 Object True if the -a option is specified on the command line=
$-d =E2=86=92 Object Synonym for $DEBUG.
$-i =E2=86=92 String If in-place edit mode is enabled (perhaps using the -i=
command-line option), $-i holds the extension used when creating the
backup file.
$-I =E2=86=92 Array Synonym for $:
$-l =E2=86=92 Object Set to true if the -l option (which enables line-end processing) is present on the command line.
$-p =E2=86=92 Object Set to true if the -p option (which puts an implicit while gets...end loop around your program) is present on the command
line.
$-v =E2=86=92 Object Synonym for $VERBOSE.
$-w =E2=86=92 Object Synonym for $VERBOSE.
$-W =E2=86=92 Object Return the value set by the -W command-line option.
and this:

"a global variable name can be formed using $- followed by a single letter or underscore" [p 318 in PDF]

but no bare $- variable....


--047d7b86d55c5df92204db13772b--