I'd suggest extracting your conditional predicate in a dedicated method.
line = line.center(SPACES).green.bold if winner?(winner, line)

Depending on your app you could also create a class that encapsulates line
itself and provides useful methods.

z = MyClassForLineHandling.new(line)
z.highlight(center: SPACES) if z.winner?(winner)

But again, that would only be worth if you perform many operations on line
and could benefit more from something like this.

Em qui, 16 de mar de 2017 08:41, 向 <liuxiang921 / gmail.com>escreveu:

> line = line.center(SPACES).green.bold if winner&.all? {|e|
> line.include?(e.to_s) }
>
> Nathan Guilty <ruby / e-solutions.re>于2017年3月16日周四 下午3:29写道:
>
> winner is an array, for example : [20.121918907, "Guest"]
> ln is a string, for example : "| Guest |    7     | 9.415871532  |"
>
> Le 2017-03-16 11:01, Nathan Guilty a crit :
> > Hello,
> >
> > How can i refactor the following ?
> >
> > --8<--
> >
> > line = line.center(SPACES).green.bold \
> >   if winner && line.include?(winner[0].to_s) &&
> > line.include?(winner[1].to_s)
> >
> > -->8--
> >
> > Thank you very much for your help.
> >
> >
> > Cheers,
> >
> > /Nathan
> >
> >
> >
> >
> >
> >
> > Unsubscribe:
> > <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
> > <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>
> Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>
>
> Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
>
(supressed text/html)
Unsubscribe: <mailto:ruby-talk-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>