It is easy to have a condition at the head of a chain and share the rest:
if condition
get_this
else
get_that
end
.foo.bar.baz
But often, I want a condition in the middle or at the tail of a chain. The best I can think of is using instance_eval
:
foo.bar
.instance_eval{
if condition
get_this
else
get_that
end
}
.baz
But I have concern that calling instance_eval
is heavy, so I actually end up not doing it. Is it worth doing so? Is there a better way, or should I just simply write:
if condition
foo.bar.get_this
else
foo.bar.get_that
end
.baz