From: Gary Weaver Date: 2012-09-27T04:50:16+09:00 Subject: Adding method on module class to yield and allow setting of attributes? I have this Module: module MyModule class << self attr_accessor :foo alias_method :foo?, :foo end end I can do: MyModule.foo # nil MyModule.foo = true MyModule.foo # true I would like to be able to do this: MyModule.configure do foo = false end Such that MyModule.foo would then return false: MyModule.foo # false I'm a little tired so I'm probably making a mistake: module MyModule class << self attr_accessor :foo alias_method :foo?, :foo # def configure(&block); yield; end # doesn't work end end # doesn't work either #class << MyModule # def configure(&block); yield; end #end Thanks in advance for any advice. I'd rather not use any Active*/Rails-specific method and don't want to use Struct, OpenStruct, etc. I just want to be able to call the methods created by the attr_accessor I used to set and get attributes. The reasons I'm doing this to a module and not a class is it is convenient since it is the module that my Gem's classes use. -- Posted via http://www.ruby-forum.com/.