Name Date Size #Lines LOC

..--

ext/H25-Apr-2025-713580

READMEH A D25-Apr-20251.4 KiB7754

RakefileH A D25-Apr-2025434 1814

README

1# << Usage >>
2
3# you can feed this README to irb and see the result
4# $ irb README
5
6# IMPORTANT NOTICE:
7# be careful with big *fixnum* (plain int) values in configs
8# int is 32 bit, but ruby fixnum is only 31!
9# For example, 2100000000 will be read as -47483648.
10
11require 'rconfig'
12c = Config.new
13
14c.read!('test.cfg')
15# => IOError
16c.read('test.cfg')
17# => false
18
19p c['some_var']
20# => SettingNotFoundError
21# note: Config#lookup is alias for Config#[]
22
23c.append 'fixnum', Config::Fixnum.new(150)
24# #<Config::Fixnum...>
25
26f1 = Config::Fixnum.new(1)
27c.append 'another_fixnum', f1
28
29f2 = Config::Fixnum.new(256)
30c.append 'next_fixnum', f2
31
32p c.size
33# => 3
34
35c.delete(f1)            # by element
36c.delete(0)             # by index
37c.delete('next_fixnum') # by name
38# note: (at now) you cannot delete nested elements by Config#delete
39#       you can do c['nested.element'].parent.delete(c['nested.element'])
40
41p c.size
42# => 0
43
44l = Config::List.new
45c.append 'the_list', l
46
47l.append Config::String.new("abcdef")
48l << Config::Float.new(3.14)
49# note: Config::List#append and Config::Array#append both have
50#       aliases Config::[Aggregate]#<<
51
52p l.name
53# => "the_list"
54
55p l.index
56# => 0
57
58p l.root?
59# => false
60
61p l.size
62# => 3
63
64l[0].format = Config::FORMAT_HEX
65
66p l[1].value
67# => 3.14
68
69l[1].value = 2.71828
70
71c.write 'test.cfg'
72
73# you will get test.cfg with following contents:
74#
75# the_list = ( "abcdef", 2.71828, 0x2A );
76#
77