Skip to content

Instantly share code, notes, and snippets.

@brianewing
Created October 31, 2012 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brianewing/3986912 to your computer and use it in GitHub Desktop.
Save brianewing/3986912 to your computer and use it in GitHub Desktop.
Ruby bucket
# sometimes I just want a quick-and-dirty thing to shove attributes onto without caring.
class Bucket
def method_missing(*args)
prop = args.first.to_s.sub(/\=$/, '').to_sym
self.class.send :attr_accessor, prop
send *args
end
end
foo = Bucket.new
foo.anything = 'heh'
foo.other # => nil
foo.inspect # => #<Bucket:... @anything="heh">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment