Refactoring unless statement

Hey guys,

As fairly new Rubyist here – I am doing a few ruby challenges to
sharpen up my skills albeit I am having trouble refactoring an unless
statement.

Doing a full unless statement is sometimes too much. How can I refactor
the method below to use a single-line unless statement.

games = [“Super Mario Bros.”, “Contra”, “Metroid”, “Mega Man 2”]
unless games.empty?
puts “Games in your vast collection: #{games.count}”
end

puts “Games in your vast collection: #{games.count}” unless games.empty?

Ruby’s pretty intuitive like that.

Thanks Joel!

On Mon, Apr 1, 2013 at 12:07 AM, Anthony P. [email protected]
wrote:

Another option

games.empty? or puts “Games in your vast collection: #{games.count}”

Cheers

robert

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs