Skip to content

Instantly share code, notes, and snippets.

@epitron
Created November 11, 2012 00:28
Show Gist options
  • Save epitron/4053145 to your computer and use it in GitHub Desktop.
Save epitron/4053145 to your computer and use it in GitHub Desktop.
class CodeWriter
VALID_OPTIONS = %w[
q
r
s
t
u
v
w
x
y
z
]
attr_accessor :output, :opts
def initialize(output, opts={})
@opts = opts
@output = output
end
VALID_OPTIONS.each do |opt_name|
define_method(opt_name) do |*args|
if args.any?
opts[opt_name] = args
else
opts[opt_name] = !opts[opt_name]
end
self
end
end
def to_s
[output, opts]
end
end
if $0 == __FILE__
p CodeWriter.new("thingy").x.y(5).z.to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment