Class: StaticStruct::Structure

Inherits:
Object
  • Object
show all
Defined in:
lib/static_struct/structure.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Structure

Returns a new instance of Structure.



7
8
9
10
# File 'lib/static_struct/structure.rb', line 7

def initialize(hash)
  @static_methods = SortedSet.new
  define_structure(hash)
end

Instance Attribute Details

#static_methodsObject (readonly)

Returns the value of attribute static_methods.



5
6
7
# File 'lib/static_struct/structure.rb', line 5

def static_methods
  @static_methods
end

Instance Method Details

#==(other) ⇒ Object



24
25
26
# File 'lib/static_struct/structure.rb', line 24

def ==(other)
  current_state == other.current_state
end

#eachObject



28
29
30
31
32
# File 'lib/static_struct/structure.rb', line 28

def each
  static_methods.each do |m|
    yield m, public_send(m)
  end
end

#inspectObject



20
21
22
# File 'lib/static_struct/structure.rb', line 20

def inspect
  to_s
end

#to_sObject



12
13
14
15
16
17
18
# File 'lib/static_struct/structure.rb', line 12

def to_s
  joined_line = [self.class, current_state].map(&:to_s).select do |str|
    str.size > 0
  end.join(' ')

  "#<#{joined_line}>"
end