Created
August 30, 2012 07:13
-
-
Save Burgestrand/3523640 to your computer and use it in GitHub Desktop.
A whitespace thingy in Ruby, just for the lulz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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