Skip to content

Instantly share code, notes, and snippets.

@huseyin
Last active July 2, 2016 18:14
Show Gist options
  • Save huseyin/495d6d3895e0739850f7665f9fbcf802 to your computer and use it in GitHub Desktop.
Save huseyin/495d6d3895e0739850f7665f9fbcf802 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: utf-8
class Hash
def make_attr
each_pair do |key, value|
self.class.send :define_method, key.to_s, Proc.new { value }
end
end
def attr_tracker
self.class.send :define_method, '[]=', Proc.new { |key, value|
update key => value
make_attr
}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment