Skip to content

Instantly share code, notes, and snippets.

@dblack
Created June 19, 2010 15:42
Show Gist options
  • Save dblack/445000 to your computer and use it in GitHub Desktop.
Save dblack/445000 to your computer and use it in GitHub Desktop.
class Bar
attr_reader :hash
def method_missing(m, *args)
if m.to_s =~ /((set|get)_(.+))/
func =
case $2
when 'set' then lambda {|value| @hash ||= {}; @hash[$3] = value}
when 'get' then lambda {@hash ||= {}; @hash[$3]}
end
self.class.send(:define_method, $1, &func)
send(m,*args)
else
super
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment