From: Bulat Ziganshin Date: 2003-02-27T22:16:09+09:00 Subject: Re: Return Values of [] for Array, Hash,... (ruby 1.6.8) Hello Brian, Thursday, February 27, 2003, 4:06:41 PM, you wrote: >> > ALL TYPES ARE HANDLED SAME WAY. >> This is completely clear. Question (NOT TO BE DISCUSSED NOW) is, >> which;), why;), couldn't it be done better;), ... ? >> >> To make the problem clearer: >> def fu, h, key, &b, o >> e = h[key] >> b.call(e,o) # should modify e >> end >> If e is of type Integer (for example), h[key] will not be modified), >> if e is of type Object, h[key] will be modified. BC> But Integer is also an Object (it's a subclass). There is no inconsistency. BC> Whatever function 'b' does, it is unable to change e. It can make method BC> calls to the object referenced by e, though, which may in turn change its BC> state if it contains instance variables. BC> Integers do not contain instance variables, and therefore there is no state BC> to change. i can add that, to be exact, some types has methods which change internal object state (whose names ends with "=" or "!", typically) and some types don't have such methods. someone can create unmodifable types, it's easy: class Persistent end class Persistent2 attr_reader :x,:y def initialize(a,b) x=a y=b end end -- Best regards, Bulat mailto:bulatz@integ.ru