Hi All,
Recently I was in a situation where I needed to add a functionality
to
a method but I couldn’t change the method signature as people in my team
were using the same method at many places.I joined the team late so it
was
not envisioned that my part will bring in need for few changes.I
couldn’t
create a new method as
it wont be dry.The case was I needed to merge few key,value pairs in
side
the hash present in method.These were not same all the time.
the method was–>
def doThing var1,var2
html_options #already defined the basic things needed for
functionality
in this hash
end
I made changes within the method -->
def doThing var1,var2
html_options.merge! :onclick => yield if block_given?
end
so calling it doThing(“one”,“two”) {“methodCalledOnClick()”} did the
trick
other people were happy using it doThing “one”,“two”
I hope I was able to explain my situation.
I’ll appreciate if you give few inputs how you people would have done
the
same thing or guide me to do this in a better fashion.