In the next version of Ruby I'd like to be able to have @number in this:
class A
def initialize
@number = 1
end
def foo(number = 2)
@number =|| number
end
end
evaluate to this:
A.new.foo
=> 2
This is nice when you want to override a class instance variable only if a non-null argument is passed. Otherwise, I commonly have to do assignments like this:
def foo(number = 2)
@number = number || @number
end
Could be cleaner. What say you?
This also has the neat side-effect of $row not living beyond that loop and therefore being eligible for garbage collection sooner (in languages that do GC anyway).
Posted by: Danny DeMichele Entrepreneur | February 09, 2011 at 02:05 AM