Question about rb_cvar_set

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

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.

···

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?

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

Dan

···

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.