Created
October 31, 2012 13:04
-
-
Save brianewing/3986912 to your computer and use it in GitHub Desktop.
Ruby bucket
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
# 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