Class: Hash
- Defined in:
- lib/cosmos/core_ext/hash.rb,
lib/cosmos/io/json_rpc.rb,
lib/cosmos/config/meta_config_parser.rb
Overview
COSMOS specific additions to the Ruby Hash class
Instance Method Summary collapse
-
#as_json(options = nil) ⇒ Object
:nodoc:.
-
#inspect(max_elements = 10) ⇒ String
String representation of the hash.
-
#old_inspect ⇒ Object
Redefine inspect to only print for small numbers of items.
- #to_meta_config_yaml(indentation = 0) ⇒ Object
Instance Method Details
#as_json(options = nil) ⇒ Object
:nodoc:
108 109 110 111 112 |
# File 'lib/cosmos/io/json_rpc.rb', line 108 def as_json( = nil) #:nodoc: pairs = [] self.each { |k, v| pairs << k.to_s; pairs << v.as_json() } Hash[*pairs] end |
#inspect(max_elements = 10) ⇒ String
Returns String representation of the hash.
30 31 32 33 34 35 36 |
# File 'lib/cosmos/core_ext/hash.rb', line 30 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_inspect ⇒ Object
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
25 |
# File 'lib/cosmos/core_ext/hash.rb', line 25 alias old_inspect inspect |
#to_meta_config_yaml(indentation = 0) ⇒ Object
32 33 34 |
# File 'lib/cosmos/config/meta_config_parser.rb', line 32 def (indentation = 0) Psych.dump(self).split("\n")[1..-1].join("\n#{' ' * indentation}") end |