Skip to content

Instantly share code, notes, and snippets.

@reinh
Created May 31, 2010 02:53
Show Gist options
  • Save reinh/419496 to your computer and use it in GitHub Desktop.
Save reinh/419496 to your computer and use it in GitHub Desktop.
def step(state, c)
case state
when :before
if c == "\n"
print "\n"
else
if c != ' '
print c
state = :inside
end
end
when :inside
case c
when ' '
state = :after
when "\n"
print "\n"
state = :before
else
print c
end
when :after
if c == "\n"
print "\n"
state = :before
end
end
end
loop do
step(:before, STDIN.read(1))
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment