G
Gavin Kistner
The question is, is it possible to change the return value of a foo=
method to NOT be the argument?
If the answer is no, well, I can sort of see why (consistency of
expectations for something like: bar = obj.foo+=3) but I also feel
like...if it's a method, it's a method, whatever syntax is invoking it.
Shouldn't I be able to control the return value?
Please see the code below.
########################
class MutableTime
...
def date
@t.day
end
def date=(n)
@t+=(n-date)*DINS
self # < == LOOK HERE!
end
...
end
########################
puts t3 = MutableTime.new("2/8/2004 2:37:13pm")
=> Sun Feb 08 14:37:13 MST 2004
puts t3.date
=>8
puts t3.date=11
=> 11 # <== GRR! I want the object instance to be the return value
puts t3.date
=> 11
puts t3
=> Wed Feb 11 14:37:13 MST 2004
method to NOT be the argument?
If the answer is no, well, I can sort of see why (consistency of
expectations for something like: bar = obj.foo+=3) but I also feel
like...if it's a method, it's a method, whatever syntax is invoking it.
Shouldn't I be able to control the return value?
Please see the code below.
########################
class MutableTime
...
def date
@t.day
end
def date=(n)
@t+=(n-date)*DINS
self # < == LOOK HERE!
end
...
end
########################
puts t3 = MutableTime.new("2/8/2004 2:37:13pm")
=> Sun Feb 08 14:37:13 MST 2004
puts t3.date
=>8
puts t3.date=11
=> 11 # <== GRR! I want the object instance to be the return value
puts t3.date
=> 11
puts t3
=> Wed Feb 11 14:37:13 MST 2004