Attr_ type thingies

Still not 100% clear about the whole metaclass concept. In the following
code:

class Module

synchronised readers

def sync_reader(mutexname, *args)
args.each {|var|
module_eval <<-here
def #{var.to_s}
#{mutexname}.synchronize {@#{var.to_s}}
end
here
}
end
end

should it be module_eval or instance_eval, and why?

martin

:

class Module
  # synchronised readers
  def sync_reader(mutexname, *args)
    args.each {|var|
      module_eval <<-here
      def #{var.to_s}

         instance method

class Module
  # synchronised readers
  def sync_reader(mutexname, *args)
    args.each {|var|
      instance_eval <<-here
      def #{var.to_s}

       class method

Guy Decoux

Thanks - took me a good bit of thinking, but I think I’ve finally
understood what module_eval does.

martin

···

ts decoux@moulon.inra.fr wrote:

class Module

synchronised readers

def sync_reader(mutexname, *args)
args.each {|var|
module_eval <<-here
def #{var.to_s}

    instance method