Class: Class

Inherits:
Object show all
Defined in:
lib/infra/ospf_common.rb

Instance Method Summary collapse

Instance Method Details

#attr_checked(attribute, &validation) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/infra/ospf_common.rb', line 27

def attr_checked(attribute, &validation)
  define_method "#{attribute}=" do |val|
    raise "Invalid attribute #{val.inspect}" unless validation.call(val)
    instance_variable_set("@#{attribute}", val)
  end
  define_method attribute do
    instance_variable_get "@#{attribute}"
  end
end

#attr_writer_delegate(*args) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/infra/ospf_common.rb', line 36

def attr_writer_delegate(*args)
  # p self
  args.each do |name|
    define_method "#{name}=" do |value|
      # p "in method..", self.class
      instance_variable_set("@#{name}", 
              self.class.const_get(name.to_s.to_camel.to_sym).new(value))
    end
  end
end