Skip to content

Instantly share code, notes, and snippets.

@flash-gordon
Created April 30, 2015 21:44
Show Gist options
  • Save flash-gordon/134394d0201df65f94f3 to your computer and use it in GitHub Desktop.
Save flash-gordon/134394d0201df65f94f3 to your computer and use it in GitHub Desktop.
define_method :create do |field, &block|
define_method "#{field}=" do |arg|
instance_variable_set(:"@#{field}", arg)
end
define_method "#{field}" do
puts instance_exec(&block)
instance_variable_get(:"@#{field}")
end
end
A = Class.new do
create('a'){ hello }
def hello
"Hello!"
end
end
o = A.new
o.a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment