Hi,
I need to write some instance method, something like this (code in ruby):
def foo_bar(param)
foo(param)
if some_condition
do_bar(param)
else
do_baz(param)
end
end
Method foo_bar is a public api.
But I think, param variable here appears too many times. Maybe it would be better to create an private instance variable and use it in foo, do_bar and do_baz method? Like here: (@param
is an instance variable in ruby, it can be initialized any time)
def foo_bar(param)
@param = param
foo
if some_condition
do_bar
else
do_baz
end
end
Which code is better? And why?