Class: Hash
- Defined in:
- lib/cosmos/core_ext/hash.rb,
lib/cosmos/io/json_rpc.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.
Instance Method Details
#as_json(options = nil) ⇒ Object
:nodoc:
80 81 82 83 84 |
# File 'lib/cosmos/io/json_rpc.rb', line 80 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.
21 22 23 24 25 26 27 |
# File 'lib/cosmos/core_ext/hash.rb', line 21 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
16 |
# File 'lib/cosmos/core_ext/hash.rb', line 16 alias old_inspect inspect |