Class: Float

Inherits:
Object show all
Defined in:
lib/ffi_yajl/json_gem.rb,
lib/ffi_yajl/ffi/encoder.rb

Instance Method Summary collapse

Instance Method Details

#ffi_yajl(yajl_gen, state) ⇒ Object



179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'ext/ffi_yajl/ext/encoder/encoder.c', line 179

def ffi_yajl(yajl_gen, state)
  str = self.to_s
  if str == "NaN" || str == "Infinity" || str == "-Infinity"
    raise ::FFI_Yajl::EncodeError.new("'#{str}' is an invalid number")
  end
  if state[:processing_key]
    if ( status = FFI_Yajl.yajl_gen_string(yajl_gen, str, str.bytesize) ) != 0
      FFI_Yajl::Encoder.raise_error_for_status(status)
    end
  else
    if ( status = FFI_Yajl.yajl_gen_number(yajl_gen, str, str.bytesize) ) != 0
      FFI_Yajl::Encoder.raise_error_for_status(status)
    end
  end
end

#to_json(*opts, &block) ⇒ Object



75
76
77
# File 'lib/ffi_yajl/json_gem.rb', line 75

def to_json(*opts, &block)
  FFI_Yajl::Encoder.encode(self)
end