matz / zetabits.com (Yukihiro Matsumoto) writes:

> Hi,
> 
> In message "[ruby-talk:4872] Re: FEATURE REQUEST: Fixnum bitfields"
>     on 00/09/12, Dave Thomas <Dave / thomases.com> writes:
> 
> |> |I just realized that the '[]=' is not implimented for Fixnum and Bignum.
> |> |Add that to my feature request. :)
> |> 
> |> I don't think it's possible, since Numbers are immutable.
> |> There's no way to change a value in a variable by invoking a method.
> |
> |Is it a different operation than (say) Fixnum#<< or Fixnum#+ ?
> |Wouldn't it just return a new Fixnum?
> 
> Fixnum#+ returns new fixnum.  But you probably want
> 
>   foo = 0xff
>   foo[1,1] = 0

True, but you could do it with

   foo = foo.withBits(1, 1, 0)

You just can't use the [] notation as it would change the semantics
for just this special case.

FWIW, I agree that BitVector is a better (and more portable) way to
go.


Regards


Dave