module Structure
A tiny library for lazy parsing data with memoized attributes
Constants
- VERSION
Private Class Methods
included(base)
click to toggle source
# File lib/structure.rb, line 8 def included(base) if base.is_a?(Class) base.extend ClassMethods else def base.included(base) ::Structure.send(:included, base) end end end
Public Instance Methods
==(other)
click to toggle source
Calls superclass method
# File lib/structure.rb, line 45 def ==(other) if public_methods(false).include?(:<=>) super else attributes == other.attributes end end
attribute_names()
click to toggle source
# File lib/structure.rb, line 19 def attribute_names self.class.attribute_names end
eql?(other)
click to toggle source
# File lib/structure.rb, line 53 def eql?(other) return false if other.class != self.class self == other end
freeze()
click to toggle source
Calls superclass method
# File lib/structure.rb, line 59 def freeze attribute_names.each { |key| send(key) } super end
inspect()
click to toggle source
# File lib/structure.rb, line 33 def inspect detail = if public_methods(false).include?(:to_s) to_s else to_a.map { |key, val| "#{key}=#{val.inspect}" }.join(', ') end "#<#{self.class.name || '?'} #{detail}>" end
Also aliased as: to_s
marshal_dump()
click to toggle source
# File lib/structure.rb, line 64 def marshal_dump attributes.values end
marshal_load(data)
click to toggle source
# File lib/structure.rb, line 68 def marshal_load(data) @mutex = ::Thread::Mutex.new attribute_names.zip(data).each do |key, val| instance_variable_set(:"@#{key}", val) end end
to_a()
click to toggle source
# File lib/structure.rb, line 23 def to_a attribute_names.map { |key| [key, send(key)] } end
to_h()
click to toggle source
# File lib/structure.rb, line 27 def to_h Hash[to_a] end
Also aliased as: attributes
Private Instance Methods
with_mutex(&block)
click to toggle source
# File lib/structure.rb, line 77 def with_mutex(&block) @mutex.owned? ? block.call : @mutex.synchronize { block.call } end