Skip to content

Instantly share code, notes, and snippets.

@Burgestrand
Created August 30, 2012 07:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Burgestrand/3523640 to your computer and use it in GitHub Desktop.
Save Burgestrand/3523640 to your computer and use it in GitHub Desktop.
A whitespace thingy in Ruby, just for the lulz
# coding: utf-8
class Whitespace
def initialize(&block)
@data = 0
@pos = -1
instance_eval(&block)
end
def  
tap { @pos += 1 }
end
def   
tap { @data |= 1 << (@pos += 1) }
end
def    
print @data.chr
@data = 0
@pos = -1
end
def HALP?(string)
program = string.bytes.map do |byte|
8.times.map do |i|
" " + " " * byte[i]
end.join(".") + ".   "
end
puts program.join("\n")
end
end
# This actually prints Hello world
Whitespace.new do
 . . .  . . .  . .   
  . .  . . .  .  . .   
 . .  .  . .  .  . .   
 . .  .  . .  .  . .   
  .  .  .  . .  .  . .   
 . . . . .  . . .   
  .  .  . .  .  .  . .   
  .  .  .  . .  .  . .   
 .  . . .  .  .  . .   
 . .  .  . .  .  . .   
 . .  . . .  .  . .   
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment