Module: Packet::ClassHelpers

Included in:
Packet::Core::ClassMethods, Pimp
Defined in:
lib/packet/packet_helper.rb

Class Method Summary collapse

Class Method Details

.iattr_accessor(*args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/packet/packet_helper.rb', line 5

def iattr_accessor *args
  metaclass.instance_eval do
    attr_accessor *args
    args.each do |attr|
      define_method("set_#{attr}") do |b_value|
        self.send("#{attr}=",b_value)
      end
    end
  end

  args.each do |attr|
    class_eval do
      define_method(attr) do
        self.class.send(attr)
      end
      define_method("#{attr}=") do |b_value|
        self.class.send("#{attr}=",b_value)
      end
    end
  end
end

.inheritable_attribute(*options_args) ⇒ Object

end of method iattr_accessor



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/packet/packet_helper.rb', line 27

def inheritable_attribute *options_args
  option_hash = options_args.last
  args = options_args[0..-2]
  args.each {|attr| instance_variable_set(:"@#{attr}",option_hash[:default] || nil )}
  metaclass.instance_eval { attr_accessor *args }
  args.each do |attr|
    class_eval do
      define_method(attr) do
        self.class.send(attr)
      end
      define_method("#{attr}=") do |b_value|
        self.class.send("#{attr}=",b_value)
      end
    end
  end
end

.metaclassObject



3
# File 'lib/packet/packet_helper.rb', line 3

def metaclass; class << self; self; end; end