Skip to content

Instantly share code, notes, and snippets.

@Electron-libre
Created June 18, 2013 12:21
Show Gist options
  • Save Electron-libre/5804923 to your computer and use it in GitHub Desktop.
Save Electron-libre/5804923 to your computer and use it in GitHub Desktop.
Ruby's dynamic accessors demo. Enjoy Ruby power :)
module Openerp
def self.define_setter(attr)
class_eval("def self.#{attr}=(val) \n @@#{attr} = val \n end \n", __FILE__, __LINE__+1)
end
def self.define_getter(attr)
class_eval("def self.#{attr} \n @@#{attr} \n end \n", __FILE__, __LINE__+1)
end
[:host, :port, :common, :object, :base].each do |attr|
define_setter(attr)
define_getter(attr)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment