Module: Tomlib

Defined in:
lib/tomlib.rb,
lib/tomlib/error.rb,
lib/tomlib/dumper.rb,
lib/tomlib/version.rb,
ext/tomlib/tomlib.c

Overview

Main library namespace

Examples:

parsing TOML data into Ruby Hash


puts Tomlib.load(<<~TOML)
  firstName = "John"
  lastName = "Doe"
TOML

# => { 'firstName' => 'John', 'lastName' => 'Doe' }

generating TOML from Ruby Hash


puts Tomlib.dump({ 'firstName' => 'John', 'lastName' => 'Doe' })

# =>
firstName = "John"
lastName = "Doe"

Defined Under Namespace

Classes: DumpError, Dumper, ParseError

Constant Summary collapse

VERSION =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

'0.7.2'

Class Method Summary collapse

Class Method Details

.dump(hash, indent: true) ⇒ String

Dump Ruby Hash into TOML format

Examples:

puts Tomlib.dump({ 'firstName' => 'John', 'lastName' => 'Doe' })
# =>
firstName = "John"
lastName = "Doe"

Parameters:

  • hash (Hash)
  • indent (true, false) (defaults to: true)

    (default: true)

Returns:

  • (String)


44
45
46
# File 'lib/tomlib.rb', line 44

def self.dump(hash, indent: true)
  Dumper.new(use_indent: indent).dump(hash)
end

.load(rb_str) ⇒ Object

Function exposed to Ruby’s world as Tomlib.load(data)



310
311
312
# File 'ext/tomlib/tomlib.c', line 310

static VALUE tomlib_load(VALUE self, VALUE rb_str) {
  return rb_rescue2(tomlib_load_do, rb_str, tomlib_load_rescue, Qnil, rb_eArgError, 0);
}