Class: Object

Inherits:
BasicObject
Defined in:
lib/infra/ospf_common.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
# File 'lib/infra/ospf_common.rb', line 103

def method_missing(method, *args, &block)
  # puts "COMMON method_missing: #{method}"

  if method.to_s =~ /^to_s(\d+)/
    to_s($1.to_i)
  else
    # p caller
    super
  end
end

Instance Method Details

#define_to_sObject



113
114
115
116
117
118
119
120
121
# File 'lib/infra/ospf_common.rb', line 113

def define_to_s
  if defined?($style)
    self.class.class_eval { eval("alias :to_s :to_s_#{$style}") }
  elsif respond_to?(:to_s_default)
    self.class.class_eval { alias :to_s :to_s_default }
  else
    puts "You're screwed!"
  end      
end

#to_bitstringObject



96
97
98
99
100
101
102
# File 'lib/infra/ospf_common.rb', line 96

def to_bitstring
  if self.respond_to?(:encode)
    self.enc.unpack('B*')[0]
  else
    ""
  end
end

#to_shex(*args) ⇒ Object



85
86
87
# File 'lib/infra/ospf_common.rb', line 85

def to_shex(*args)
  self.respond_to?(:encode) ? self.encode(*args).unpack('H*')[0] : ""
end

#to_shex4_len(len, *args) ⇒ Object



92
93
94
95
# File 'lib/infra/ospf_common.rb', line 92

def to_shex4_len(len, *args)
  s = to_shex4(*args)
  "#{s[0..len]}#{s.size>len ? '...' : ''}"
end

#to_shex_len(len, *args) ⇒ Object



88
89
90
91
# File 'lib/infra/ospf_common.rb', line 88

def to_shex_len(len, *args)
  s = to_shex(*args)
  "#{s[0..len]}#{s.size>len ? '...' : ''}"
end