Class: Hash

Inherits:
Object show all
Defined in:
lib/openc3/core_ext/hash.rb,
lib/openc3/io/json_rpc.rb,
lib/openc3/config/meta_config_parser.rb

Overview

OpenC3 specific additions to the Ruby Hash class

Instance Method Summary collapse

Instance Method Details

#as_json(options = nil) ⇒ Object

:nodoc:



117
118
119
120
121
# File 'lib/openc3/io/json_rpc.rb', line 117

def as_json(options = nil) #:nodoc:
  hash = {}
  self.each {|k,v| hash[k.to_s] = v.as_json(options) }
  hash
end

#inspect(max_elements = 10) ⇒ String

Returns String representation of the hash.

Parameters:

  • max_elements (Integer) (defaults to: 10)

    The maximum number of elements in the Hash to print out before simply displaying the Hash class and object id

Returns:

  • (String)

    String representation of the hash



33
34
35
36
37
38
39
# File 'lib/openc3/core_ext/hash.rb', line 33

def inspect(max_elements = 10)
  if self.length <= max_elements
    old_inspect()
  else
    '#<' + self.class.to_s + ':' + self.object_id.to_s + '>'
  end
end

#old_inspectObject

Redefine inspect to only print for small numbers of items. Prevents exceptions taking forever to be raised with large objects. See blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/105145



28
# File 'lib/openc3/core_ext/hash.rb', line 28

alias old_inspect inspect

#to_meta_config_yaml(indentation = 0) ⇒ Object



35
36
37
# File 'lib/openc3/config/meta_config_parser.rb', line 35

def to_meta_config_yaml(indentation = 0)
  Psych.dump(self).split("\n")[1..-1].join("\n#{' ' * indentation}")
end