Class: Module

Inherits:
Object show all
Defined in:
lib/rbot/core/utils/extends.rb

Overview

Extensions to the Module class

Instance Method Summary collapse

Instance Method Details

#define_structure(name, *members) ⇒ Object

Many plugins define Struct objects to hold their data. On rescans, lots of warnings are echoed because of the redefinitions. Using this method solves the problem, by checking if the Struct already exists, and if it has the same attributes



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/rbot/core/utils/extends.rb', line 23

def define_structure(name, *members)
  sym = name.to_sym
  if Struct.const_defined?(sym)
    kl = Struct.const_get(sym)
    if kl.new.members.map { |member| member.intern } == members.map
      debug "Struct #{sym} previously defined, skipping"
      const_set(sym, kl)
      return
    end
  end
  debug "Defining struct #{sym} with members #{members.inspect}"
  const_set(sym, Struct.new(name.to_s, *members))
end