Class | Module |
In: |
lib/rbot/core/utils/extends.rb
|
Parent: | Object |
Extensions to the Module class
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
# File lib/rbot/core/utils/extends.rb, line 23 23: def define_structure(name, *members) 24: sym = name.to_sym 25: if Struct.const_defined?(sym) 26: kl = Struct.const_get(sym) 27: if kl.new.members.map { |member| member.intern } == members.map 28: debug "Struct #{sym} previously defined, skipping" 29: const_set(sym, kl) 30: return 31: end 32: end 33: debug "Defining struct #{sym} with members #{members.inspect}" 34: const_set(sym, Struct.new(name.to_s, *members)) 35: end