I've been wondering about the best way to quickly create a "bang"
version of a method (specifically one which overwrites self). Is there a
better DRY approach than the below?
I guess that there's probably a way to input a list of methods as
symbols and output bang versions of each as new methods, but at the
moment I'm more interested in the wording of the bang method itself.
This is the best I can come up with (in pseudo-code):
def test( arg1, arg2, arg3=true ) #Do stuff with the args that returns a value
end
On Thu, Feb 14, 2013 at 1:06 PM, Joel Pearson <lists@ruby-forum.com> wrote:
I've been wondering about the best way to quickly create a "bang"
version of a method (specifically one which overwrites self). Is there a
better DRY approach than the below?
I guess that there's probably a way to input a list of methods as
symbols and output bang versions of each as new methods, but at the
moment I'm more interested in the wording of the bang method itself.
This is the best I can come up with (in pseudo-code):
def test( arg1, arg2, arg3=true ) #Do stuff with the args that returns a value
end
That's an interesting way to do it. If I assume that any bang method I
write in a given class would also have a non-bang method, then I could
easily have a catch-all process define the methods for me when an
instance is generated. Cool!
Yup!
Hope this helps... happy hacking.
By the way... pay attention at all the consequences of 'dup'
See: Class: Object (Ruby 1.9.3)
e.
···
On Thu, Feb 14, 2013 at 1:49 PM, Joel Pearson <lists@ruby-forum.com> wrote:
That's an interesting way to do it. If I assume that any bang method I
write in a given class would also have a non-bang method, then I could
easily have a catch-all process define the methods for me when an
instance is generated. Cool!