I keep writing the same code in Ruby, which seems to benefit from the “do” code bits, but I'm not sure how to write this method.
I keep doing this code code that starts and ends with the same lines of code ...
x.increment!(:step_count) # same each time # ...then some different code each x.update_column(:step_description, "blerg message") # same each time
I feel that it will benefit from doing something like this ...
update_steps "blerg message" do
And then inside the "do" every time it executes the general code.
How can I make a method where I can use 'do'.
Thanks!
Edit: I consider it important not to close this because I did not know to look for "block" or "yield". People who may not know these conditions may end up looking for a “do.”
source share