Class: Pollex::PollexObject

Inherits:
Object
  • Object
show all
Defined in:
lib/pollex/pollex_class.rb

Overview

Superclass for Pollex objects providing helper instance methods.

Direct Known Subclasses

Entry, Language, Level, Reconstruction, SemanticField, Source

Instance Method Summary collapse

Constructor Details

#initialize(attrs = {}) ⇒ PollexObject

Initializes objects with a hash of attributes.



7
8
9
10
11
12
13
14
# File 'lib/pollex/pollex_class.rb', line 7

def initialize(attrs={})
  super()
  attrs.each do |name, value|
    setter = "#{name.to_s}=".to_sym
    self.send(setter, value) if self.respond_to?(setter)
  end
  self
end

Instance Method Details

#inspectObject

Overrides Object#inspect to only show the attributes defined by PollexClass#attr_inspector.



19
20
21
22
23
24
25
26
# File 'lib/pollex/pollex_class.rb', line 19

def inspect
  inspectables = self.class.inspectables
  if inspectables
    "#<#{self.class}:0x#{object_id.to_s(16)} " + inspectables.map {|i| "@#{i}=\"#{send(i) rescue nil}\""}.join(' ') + ">"
  else
    super
  end
end