[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Question about rb_cvar_set

Daniel Berger

2/13/2007 7:11:00 PM

Hi,

Ruby 1.8.5 p12

It looks like there was a prototype change in rb_cvar_set() at some
point in the 1.8.x branch. It now takes a 4th parameter (an int). What
is the 4th parameter supposed to be?

Thanks,

Dan

2 Answers

George

2/14/2007 2:17:00 AM

0

On 2/14/07, Daniel Berger <djberg96@gmail.com> wrote:
> Hi,
>
> Ruby 1.8.5 p12
>
> It looks like there was a prototype change in rb_cvar_set() at some
> point in the 1.8.x branch. It now takes a 4th parameter (an int). What
> is the 4th parameter supposed to be?

Hi Dan,

If you poke your nose into the rb_cvar_set() function, you'll see it's
just a warning enabler flag. Specifically, if this argument is
nonzero, then in verbose mode (-v, -w) you'll get a warning if you
modify a class variable from a subclass. As in:

$ ruby -w -e 'class B; @@x = 1; end; class D < B; @@x = 5; end'
-e:1: warning: already initialized class variable @@x

The flag appears to be used to distinguish between cases such as:

class B
@@x = 1
end

class D < B
@@x = 2 # warning

def f
@@x = 3 # no warning
end

def self.f
@@x = 4 # no warning
end
end

Here, although the last 3 assignments to @@x all modify B's @@x, the
ones inside a def are considered "assignment-style", whereas the "@@x
= 2" is "declaration-style". Only the latter generates a warning.

Regards,
George.

Daniel Berger

2/14/2007 3:02:00 PM

0

On Feb 13, 7:17 pm, "George Ogata" <george.og...@gmail.com> wrote:
> On 2/14/07, Daniel Berger <djber...@gmail.com> wrote:
>
> > Hi,
>
> > Ruby 1.8.5 p12
>
> > It looks like there was a prototype change in rb_cvar_set() at some
> > point in the 1.8.x branch. It now takes a 4th parameter (an int). What
> > is the 4th parameter supposed to be?
>
> Hi Dan,
>
> If you poke your nose into the rb_cvar_set() function, you'll see it's
> just a warning enabler flag. Specifically, if this argument is
> nonzero, then in verbose mode (-v, -w) you'll get a warning if you
> modify a class variable from a subclass. As in:
>
> $ ruby -w -e 'class B; @@x = 1; end; class D < B; @@x = 5; end'
> -e:1: warning: already initialized class variable @@x
>
> The flag appears to be used to distinguish between cases such as:
>
> class B
> @@x = 1
> end
>
> class D < B
> @@x = 2 # warning
>
> def f
> @@x = 3 # no warning
> end
>
> def self.f
> @@x = 4 # no warning
> end
> end
>
> Here, although the last 3 assignments to @@x all modify B's @@x, the
> ones inside a def are considered "assignment-style", whereas the "@@x
> = 2" is "declaration-style". Only the latter generates a warning.

Ah, thanks George. It looks like you're supposed to test for the
RB_CVAR_SET_4ARGS macro to stay backwards compatible, too.

Dan