halostatue wrote:
On 11/16/05, Eric M. [email protected] wrote:
object into a strange state.
Obviously, I wasn’t clear. I said “At a simplistic level, this is:” …
This means that this is essentially what the operation would do, but
not necessarily the full scope of what would be needed. A more “safe”
operation would be:
class Object
def replace(other)
unless other.class == self.class
raise TypeError,
“cannot convert #{self.class} into #{other.class}”
end
other.instance_variables.each do |name|
instance_variable_set(name,
other.instance_variable_get(name))
end
end
end
This is, by the way, exactly what:
a = {}
b = []
b.replace a
does. [snip]
What if the receiver of #replace has instance variables that don’t exist
in the parameter? Do you intend for them to go away? If they don’t,
you could break code that uses
if @instancevar …
Doing so would require getting both sets of instance variables etc…
On 11/17/05, J. Merrill [email protected] wrote:
unless other.class == self.class
This is, by the way, exactly what:
if @instancevar …
Doing so would require getting both sets of instance variables etc…
That’s easier than one might think. I already do a lot of this work in
Transaction::Simple.
-austin
halostatue wrote:
On 11/17/05, J. Merrill [email protected] wrote:
Doing so would require getting both sets of instance variables etc…
That’s easier than one might think. I already do a lot of this work in
Transaction::Simple.
-austin
It’s not difficult, but when you didn’t include it in your “how this
should work” sample code you left it unclear as to whether you want
existing instance vars (that don’t exist in the replacing-from object)
to be removed from the receiver. Am I right that you do want them to
be removed?
On 11/18/05, J. Merrill [email protected] wrote:
It’s not difficult, but when you didn’t include it in your “how this
should work” sample code you left it unclear as to whether you want
existing instance vars (that don’t exist in the replacing-from object)
to be removed from the receiver. Am I right that you do want them to
be removed?
Yes.
-austin