Hi --

On Wed, 29 Mar 2006, Gregory Seidman wrote:

> On Wed, Mar 29, 2006 at 12:56:25AM +0900, dblack / wobblini.net wrote:
> [...]
> } I'm talking about Ruby, not C.  In Ruby, you can modify a receiver
> } without changing its instance variables -- in fact, you can modify a
> } receiver that doesn't *have* any instance variables.
> }
> } irb(main):001:0> s = ""
> } => ""
> } irb(main):002:0> s.replace("abc")
> } => "abc"
> } irb(main):003:0> s.instance_variables
> } => []
> }
> } The term "instance variable" has a specific and unambiguous meaning in
> } Ruby.
>
> I repeat, it's a technicality. A string's internal state is held in
> variables tied to the particular instance. They are not visible to the Ruby
> runtime, however, so they are not listed in the array returned by the
> object's instance_variables method. Do you really believe that methods,
> which modify those variables, do not change the instance variables simply
> because the runtime is unaware of the variables? No, I don't think so. You
> are arguing a technicality.

I'm not arguing at all.  Someone asked a question about instance
variables (meaning Ruby instance variables, I assumed), and I answered
it.  I assume, by default, that questions about Ruby are questions
about Ruby itself, rather than the C implementation.  It's possible
that that's not what the OP meant, but in that case it's a good chance
for him to learn the customary use of the terminology.

Obviously *something* changes when you change the contents of a string
or array.  But calling it, without qualification, an "instance
variable" of the object is almost certainly a recipe for unclarity and
confusion down the road.


David

-- 
David A. Black (dblack / wobblini.net)
Ruby Power and Light, LLC (http://www.rubypowerandlight.com)

"Ruby for Rails" chapters now available
from Manning Early Access Program! http://www.manning.com/books/black