Class: Cosmos::JsonRpc

Inherits:
Object show all
Includes:
Comparable
Defined in:
lib/cosmos/io/json_rpc.rb

Overview

Base class for all JSON Remote Procedure Calls. Provides basic comparison and Hash to JSON conversions.

Direct Known Subclasses

JsonRpcError, JsonRpcRequest, JsonRpcResponse

Instance Method Summary collapse

Constructor Details

#initializeJsonRpc

Returns a new instance of JsonRpc.



154
155
156
# File 'lib/cosmos/io/json_rpc.rb', line 154

def initialize
  @hash = {}
end

Instance Method Details

#<=>(other) ⇒ Object

Parameters:

  • other (JsonRpc)

    Another JsonRpc to compare hash values with



159
160
161
# File 'lib/cosmos/io/json_rpc.rb', line 159

def <=>(other)
  self.as_json <=> other.as_json
end

#as_json(*a) ⇒ Hash

Returns Hash representing the object.

Parameters:

  • a (Array)

    Array of options

Returns:

  • (Hash)

    Hash representing the object



165
166
167
# File 'lib/cosmos/io/json_rpc.rb', line 165

def as_json(*a)
  @hash.as_json(*a)
end

#to_json(*a) ⇒ String

Returns The JSON encoded String.

Parameters:

  • a (Array)

    Array of options

Returns:

  • (String)

    The JSON encoded String



171
172
173
# File 'lib/cosmos/io/json_rpc.rb', line 171

def to_json(*a)
  as_json(*a).to_json(*a)
end