Class: Object

Inherits:
BasicObject
Defined in:
lib/bitcoin.rb

Instance Method Summary collapse

Instance Method Details

#build_jsonObject



156
157
158
159
160
161
162
# File 'lib/bitcoin.rb', line 156

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



164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'lib/bitcoin.rb', line 164

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