Skip to content

Instantly share code, notes, and snippets.

@abriening
Created January 21, 2012 18:13
Show Gist options
  • Save abriening/1653470 to your computer and use it in GitHub Desktop.
Save abriening/1653470 to your computer and use it in GitHub Desktop.
Simple ruby spinner
class Spinner
def initialize printer=nil
@spinner = %w[| / - \\]
@count = 0
@printer ||= $stderr
end
def print
@printer.print "\r"+@spinner[@count]
@count += 1
@count = 0 if @count > @spinner.size - 1
end
def self.print
@spinner ||= new
@spinner.print
end
end
# 50.times{ Spinner.print; sleep 0.1 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment