Created
November 11, 2012 00:28
-
-
Save epitron/4053145 to your computer and use it in GitHub Desktop.
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
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