I think you can simply set @name = °∆Guest°« in the constructor that way @name has a default value of °∆Guest'
> On 24 Nov 2016, at 12:30 PM, Nathan Guilty <ruby / e-solutions.re> wrote:
> 
> Hi,
> 
> With the following Ruby script :
> 
> --8<--
> class Testing
> 
>  def initialize
>    # Start with setting your name
>    your_name
>  end
> 
>  def your_name
>    # Get your name
>    puts "(Type 'quit' to exit)"
>    print 'Please your name? '
>    @name = gets.chomp.capitalize
> 
>    @name = 'Guest' if @name.empty?
>    byebye if @name == 'Quit'
> 
>    play
>  end
> 
>  def byebye
>    @name = 'Guest' if @name == 'Quit'
>    puts "\nGoodbye #{@name}.\n\n"
> 
>    exit
>  end
> 
>  def play
>    puts "Let's play #{@name}!"
>  end
> 
> end
> 
> 
> Testing.new
> 
> -->8--
> 
> How can avoid the 2 assignments of @name = 'Guest' ?
> Is it possible refactor this piece of code smaller ?
> 
> Thank you very much for your replies.
> 
> /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>