Class: Object

Inherits:
BasicObject
Defined in:
lib/bitcoin.rb

Instance Method Summary collapse

Instance Method Details

#build_jsonObject



161
162
163
164
165
166
167
# File 'lib/bitcoin.rb', line 161

def build_json
  if self.is_a?(Array)
    "[#{self.map{|o|o.to_h.to_json}.join(',')}]"
  else
    to_h.to_json
  end
end

#to_hObject



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/bitcoin.rb', line 169

def to_h
  return self if self.is_a?(String)
  instance_variables.inject({}) do |result, var|
    key = var.to_s
    key.slice!(0) if key.start_with?('@')
    value = instance_variable_get(var)
    if value.is_a?(Array)
      result.update(key => value.map{|v|v.to_h})
    else
      result.update(key => value)
    end
  end
end