P
Pedro Côrte-Real
I have this line in a class method to define an initializer:
define_methodinitialize){|value| @value = value}
But I want something more like this:
define_methodinitialize){|value=nil| @value = value if value}
which doesn't seem to be possible because of the "value=nil" part. Is
there some way to do this that isn't eval? Eval would work fine since
this is pretty static code and I have unit tests for it but I try to
avoid it if I can. I've only used it before for performance to turn
some code with runtime tests into eval-time tests.
Pedro.
define_methodinitialize){|value| @value = value}
But I want something more like this:
define_methodinitialize){|value=nil| @value = value if value}
which doesn't seem to be possible because of the "value=nil" part. Is
there some way to do this that isn't eval? Eval would work fine since
this is pretty static code and I have unit tests for it but I try to
avoid it if I can. I've only used it before for performance to turn
some code with runtime tests into eval-time tests.
Pedro.