oj 3.11.5 → 3.16.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1421 -0
  3. data/README.md +19 -5
  4. data/RELEASE_NOTES.md +61 -0
  5. data/ext/oj/buf.h +20 -6
  6. data/ext/oj/cache.c +329 -0
  7. data/ext/oj/cache.h +22 -0
  8. data/ext/oj/cache8.c +10 -9
  9. data/ext/oj/circarray.c +8 -6
  10. data/ext/oj/circarray.h +2 -2
  11. data/ext/oj/code.c +19 -33
  12. data/ext/oj/code.h +2 -2
  13. data/ext/oj/compat.c +27 -77
  14. data/ext/oj/custom.c +86 -179
  15. data/ext/oj/debug.c +126 -0
  16. data/ext/oj/dump.c +256 -249
  17. data/ext/oj/dump.h +26 -12
  18. data/ext/oj/dump_compat.c +565 -642
  19. data/ext/oj/dump_leaf.c +17 -63
  20. data/ext/oj/dump_object.c +65 -187
  21. data/ext/oj/dump_strict.c +27 -51
  22. data/ext/oj/encoder.c +43 -0
  23. data/ext/oj/err.c +2 -13
  24. data/ext/oj/err.h +24 -8
  25. data/ext/oj/extconf.rb +21 -6
  26. data/ext/oj/fast.c +149 -149
  27. data/ext/oj/intern.c +313 -0
  28. data/ext/oj/intern.h +22 -0
  29. data/ext/oj/mem.c +318 -0
  30. data/ext/oj/mem.h +53 -0
  31. data/ext/oj/mimic_json.c +121 -106
  32. data/ext/oj/object.c +85 -162
  33. data/ext/oj/odd.c +89 -67
  34. data/ext/oj/odd.h +15 -15
  35. data/ext/oj/oj.c +542 -411
  36. data/ext/oj/oj.h +99 -73
  37. data/ext/oj/parse.c +175 -187
  38. data/ext/oj/parse.h +26 -24
  39. data/ext/oj/parser.c +1600 -0
  40. data/ext/oj/parser.h +101 -0
  41. data/ext/oj/rails.c +112 -159
  42. data/ext/oj/rails.h +1 -1
  43. data/ext/oj/reader.c +11 -14
  44. data/ext/oj/reader.h +4 -2
  45. data/ext/oj/resolve.c +5 -24
  46. data/ext/oj/rxclass.c +7 -6
  47. data/ext/oj/rxclass.h +1 -1
  48. data/ext/oj/saj.c +22 -33
  49. data/ext/oj/saj2.c +584 -0
  50. data/ext/oj/saj2.h +23 -0
  51. data/ext/oj/scp.c +5 -28
  52. data/ext/oj/sparse.c +28 -72
  53. data/ext/oj/stream_writer.c +50 -40
  54. data/ext/oj/strict.c +56 -61
  55. data/ext/oj/string_writer.c +72 -39
  56. data/ext/oj/trace.h +31 -4
  57. data/ext/oj/usual.c +1218 -0
  58. data/ext/oj/usual.h +69 -0
  59. data/ext/oj/util.h +1 -1
  60. data/ext/oj/val_stack.c +14 -3
  61. data/ext/oj/val_stack.h +8 -7
  62. data/ext/oj/validate.c +46 -0
  63. data/ext/oj/wab.c +63 -88
  64. data/lib/oj/active_support_helper.rb +1 -3
  65. data/lib/oj/bag.rb +7 -1
  66. data/lib/oj/easy_hash.rb +4 -5
  67. data/lib/oj/error.rb +1 -2
  68. data/lib/oj/json.rb +162 -150
  69. data/lib/oj/mimic.rb +9 -7
  70. data/lib/oj/saj.rb +20 -6
  71. data/lib/oj/schandler.rb +5 -4
  72. data/lib/oj/state.rb +12 -8
  73. data/lib/oj/version.rb +1 -2
  74. data/lib/oj.rb +2 -0
  75. data/pages/Compatibility.md +1 -1
  76. data/pages/InstallOptions.md +20 -0
  77. data/pages/JsonGem.md +15 -0
  78. data/pages/Modes.md +8 -3
  79. data/pages/Options.md +43 -5
  80. data/pages/Parser.md +309 -0
  81. data/pages/Rails.md +14 -2
  82. data/test/_test_active.rb +8 -9
  83. data/test/_test_active_mimic.rb +7 -8
  84. data/test/_test_mimic_rails.rb +17 -20
  85. data/test/activerecord/result_test.rb +5 -6
  86. data/test/activesupport6/encoding_test.rb +63 -28
  87. data/test/{activesupport5 → activesupport7}/abstract_unit.rb +16 -12
  88. data/test/{activesupport5 → activesupport7}/decoding_test.rb +2 -10
  89. data/test/{activesupport5 → activesupport7}/encoding_test.rb +86 -50
  90. data/test/{activesupport5 → activesupport7}/encoding_test_cases.rb +6 -0
  91. data/test/{activesupport5 → activesupport7}/time_zone_test_helpers.rb +8 -0
  92. data/test/files.rb +15 -15
  93. data/test/foo.rb +16 -45
  94. data/test/helper.rb +11 -8
  95. data/test/isolated/shared.rb +3 -2
  96. data/test/json_gem/json_addition_test.rb +2 -2
  97. data/test/json_gem/json_common_interface_test.rb +8 -6
  98. data/test/json_gem/json_encoding_test.rb +0 -0
  99. data/test/json_gem/json_ext_parser_test.rb +1 -0
  100. data/test/json_gem/json_fixtures_test.rb +3 -2
  101. data/test/json_gem/json_generator_test.rb +56 -38
  102. data/test/json_gem/json_generic_object_test.rb +11 -11
  103. data/test/json_gem/json_parser_test.rb +54 -47
  104. data/test/json_gem/json_string_matching_test.rb +9 -9
  105. data/test/json_gem/test_helper.rb +7 -3
  106. data/test/mem.rb +34 -0
  107. data/test/perf.rb +22 -27
  108. data/test/perf_compat.rb +31 -33
  109. data/test/perf_dump.rb +50 -0
  110. data/test/perf_fast.rb +80 -82
  111. data/test/perf_file.rb +27 -29
  112. data/test/perf_object.rb +65 -69
  113. data/test/perf_once.rb +59 -0
  114. data/test/perf_parser.rb +183 -0
  115. data/test/perf_saj.rb +46 -54
  116. data/test/perf_scp.rb +58 -69
  117. data/test/perf_simple.rb +41 -39
  118. data/test/perf_strict.rb +74 -82
  119. data/test/perf_wab.rb +67 -69
  120. data/test/prec.rb +5 -5
  121. data/test/sample/change.rb +0 -1
  122. data/test/sample/dir.rb +0 -1
  123. data/test/sample/doc.rb +0 -1
  124. data/test/sample/file.rb +0 -1
  125. data/test/sample/group.rb +0 -1
  126. data/test/sample/hasprops.rb +0 -1
  127. data/test/sample/layer.rb +0 -1
  128. data/test/sample/rect.rb +0 -1
  129. data/test/sample/shape.rb +0 -1
  130. data/test/sample/text.rb +0 -1
  131. data/test/sample.rb +16 -16
  132. data/test/sample_json.rb +8 -8
  133. data/test/test_compat.rb +95 -43
  134. data/test/test_custom.rb +73 -51
  135. data/test/test_debian.rb +7 -10
  136. data/test/test_fast.rb +135 -79
  137. data/test/test_file.rb +41 -30
  138. data/test/test_gc.rb +16 -5
  139. data/test/test_generate.rb +5 -5
  140. data/test/test_hash.rb +5 -5
  141. data/test/test_integer_range.rb +9 -9
  142. data/test/test_null.rb +20 -20
  143. data/test/test_object.rb +99 -96
  144. data/test/test_parser.rb +11 -0
  145. data/test/test_parser_debug.rb +27 -0
  146. data/test/test_parser_saj.rb +337 -0
  147. data/test/test_parser_usual.rb +251 -0
  148. data/test/test_rails.rb +2 -2
  149. data/test/test_saj.rb +10 -8
  150. data/test/test_scp.rb +37 -39
  151. data/test/test_strict.rb +40 -32
  152. data/test/test_various.rb +165 -84
  153. data/test/test_wab.rb +48 -44
  154. data/test/test_writer.rb +47 -47
  155. data/test/tests.rb +13 -5
  156. data/test/tests_mimic.rb +12 -3
  157. data/test/tests_mimic_addition.rb +12 -3
  158. metadata +74 -128
  159. data/ext/oj/hash.c +0 -131
  160. data/ext/oj/hash.h +0 -19
  161. data/ext/oj/hash_test.c +0 -491
  162. data/test/activesupport4/decoding_test.rb +0 -108
  163. data/test/activesupport4/encoding_test.rb +0 -531
  164. data/test/activesupport4/test_helper.rb +0 -41
  165. data/test/activesupport5/test_helper.rb +0 -72
  166. data/test/bar.rb +0 -35
  167. data/test/baz.rb +0 -16
  168. data/test/zoo.rb +0 -13
data/test/perf_wab.rb CHANGED
@@ -1,131 +1,129 @@
1
1
  #!/usr/bin/env ruby
2
- # encoding: UTF-8
2
+ # frozen_string_literal: true
3
3
 
4
- $: << '.'
5
- $: << File.join(File.dirname(__FILE__), "../lib")
6
- $: << File.join(File.dirname(__FILE__), "../ext")
4
+ $LOAD_PATH << '.'
5
+ $LOAD_PATH << File.join(__dir__, '../lib')
6
+ $LOAD_PATH << File.join(__dir__, '../ext')
7
7
 
8
8
  require 'optparse'
9
9
  require 'perf'
10
10
  require 'oj'
11
11
 
12
- $verbose = false
13
- $indent = 0
14
- $iter = 20000
15
- $with_bignum = false
16
- $with_nums = true
17
- $size = 0
12
+ @verbose = false
13
+ @indent = 0
14
+ @iter = 20_000
15
+ @with_bignum = false
16
+ @with_nums = true
17
+ @size = 0
18
18
 
19
19
  opts = OptionParser.new
20
- opts.on("-v", "verbose") { $verbose = true }
21
- opts.on("-c", "--count [Int]", Integer, "iterations") { |i| $iter = i }
22
- opts.on("-i", "--indent [Int]", Integer, "indentation") { |i| $indent = i }
23
- opts.on("-s", "--size [Int]", Integer, "size (~Kbytes)") { |i| $size = i }
24
- opts.on("-b", "with bignum") { $with_bignum = true }
25
- opts.on("-h", "--help", "Show this display") { puts opts; Process.exit!(0) }
26
- files = opts.parse(ARGV)
20
+ opts.on('-v', 'verbose') { @verbose = true }
21
+ opts.on('-c', '--count [Int]', Integer, 'iterations') { |i| @iter = i }
22
+ opts.on('-i', '--indent [Int]', Integer, 'indentation') { |i| @indent = i }
23
+ opts.on('-s', '--size [Int]', Integer, 'size (~Kbytes)') { |i| @size = i }
24
+ opts.on('-b', 'with bignum') { @with_bignum = true }
25
+ opts.on('-h', '--help', 'Show this display') { puts opts; Process.exit!(0) }
26
+ opts.parse(ARGV)
27
27
 
28
- $obj = {
28
+ @obj = {
29
29
  a: 'Alpha', # string
30
30
  b: true, # boolean
31
- c: 12345, # number
32
- d: [ true, [false, [-123456789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
31
+ c: 12_345, # number
32
+ d: [ true, [false, [-123_456_789, nil], 3.9676, ['Something else.', false], nil]], # mix it up array
33
33
  e: { zero: nil, one: 1, two: 2, three: [3], four: [0, 1, 2, 3, 4] }, # hash
34
34
  f: nil, # nil
35
35
  h: { a: { b: { c: { d: {e: { f: { g: nil }}}}}}}, # deep hash, not that deep
36
36
  i: [[[[[[[nil]]]]]]] # deep array, again, not that deep
37
37
  }
38
- $obj[:g] = 12345678901234567890123456789 if $with_bignum
38
+ @obj[:g] = 12_345_678_901_234_567_890_123_456_789 if @with_bignum
39
39
 
40
- Oj.default_options = { :indent => $indent, :mode => :wab }
40
+ Oj.default_options = { :indent => @indent, :mode => :wab }
41
41
 
42
- if 0 < $size
43
- o = $obj
44
- $obj = []
45
- (4 * $size).times do
46
- $obj << o
42
+ if 0 < @size
43
+ ob = @obj
44
+ @obj = []
45
+ (4 * @size).times do
46
+ @obj << ob
47
47
  end
48
48
  end
49
49
 
50
- $json = Oj.dump($obj)
51
- $obj_json = Oj.dump($obj, :mode => :object)
52
- #puts "*** size: #{$obj_json.size}"
53
- #puts "*** #{$obj_json}"
54
- $failed = {} # key is same as String used in tests later
50
+ @json = Oj.dump(@obj)
51
+ @obj_json = Oj.dump(@obj, :mode => :object)
52
+ # puts "*** size: #{@obj_json.size}"
53
+ # puts "*** #{@obj_json}"
54
+ @failed = {} # key is same as String used in tests later
55
55
 
56
56
  def capture_error(tag, orig, load_key, dump_key, &blk)
57
- begin
58
- obj = blk.call(orig)
59
- raise "#{tag} #{dump_key} and #{load_key} did not return the same object as the original." unless orig == obj
60
- rescue Exception => e
61
- $failed[tag] = "#{e.class}: #{e.message}"
62
- end
57
+ obj = blk.call(orig)
58
+ raise "#{tag} #{dump_key} and #{load_key} did not return the same object as the original." unless orig == obj
59
+ rescue Exception => e
60
+ @failed[tag] = "#{e.class}: #{e.message}"
63
61
  end
64
62
 
65
63
  # Verify that all packages dump and load correctly and return the same Object as the original.
66
- capture_error('Oj:wab', $obj, 'load', 'dump') { |o| Oj.wab_load(Oj.dump(o, :mode => :wab)) }
67
- capture_error('Yajl', $obj, 'encode', 'parse') { |o| require 'yajl'; Yajl::Parser.parse(Yajl::Encoder.encode(o)) }
68
- capture_error('JSON::Ext', $obj, 'generate', 'parse') { |o|
64
+ capture_error('Oj:wab', @obj, 'load', 'dump') { |o| Oj.wab_load(Oj.dump(o, :mode => :wab)) }
65
+ capture_error('Yajl', @obj, 'encode', 'parse') { |o| require 'yajl'; Yajl::Parser.parse(Yajl::Encoder.encode(o)) }
66
+ capture_error('JSON::Ext', @obj, 'generate', 'parse') { |o|
69
67
  require 'json'
70
68
  require 'json/ext'
71
69
  JSON.generator = JSON::Ext::Generator
72
70
  JSON.parser = JSON::Ext::Parser
73
71
  JSON.parse(JSON.generate(o))
74
72
  }
75
- capture_error('JSON::Pure', $obj, 'generate', 'parse') { |o|
73
+ capture_error('JSON::Pure', @obj, 'generate', 'parse') { |o|
76
74
  require 'json/pure'
77
75
  JSON.generator = JSON::Pure::Generator
78
76
  JSON.parser = JSON::Pure::Parser
79
77
  JSON.parse(JSON.generate(o))
80
78
  }
81
79
 
82
- if $verbose
83
- puts "json:\n#{$json}\n"
84
- puts "object json:\n#{$obj_json}\n"
85
- puts "Oj loaded object:\n#{Oj.wab_load($json)}\n"
86
- puts "Yajl loaded object:\n#{Yajl::Parser.parse($json)}\n"
87
- puts "JSON loaded object:\n#{JSON::Ext::Parser.new($json).parse}\n"
80
+ if @verbose
81
+ puts "json:\n#{@json}\n"
82
+ puts "object json:\n#{@obj_json}\n"
83
+ puts "Oj loaded object:\n#{Oj.wab_load(@json)}\n"
84
+ puts "Yajl loaded object:\n#{Yajl::Parser.parse(@json)}\n"
85
+ puts "JSON loaded object:\n#{JSON::Ext::Parser.new(@json).parse}\n"
88
86
  end
89
87
 
90
88
  puts '-' * 80
91
- puts "Wab Parse Performance"
89
+ puts 'Wab Parse Performance'
92
90
  perf = Perf.new()
93
- unless $failed.has_key?('JSON::Ext')
94
- perf.add('JSON::Ext', 'parse') { JSON.parse($json) }
91
+ unless @failed.key?('JSON::Ext')
92
+ perf.add('JSON::Ext', 'parse') { JSON.parse(@json) }
95
93
  perf.before('JSON::Ext') { JSON.parser = JSON::Ext::Parser }
96
94
  end
97
- unless $failed.has_key?('JSON::Pure')
98
- perf.add('JSON::Pure', 'parse') { JSON.parse($json) }
95
+ unless @failed.key?('JSON::Pure')
96
+ perf.add('JSON::Pure', 'parse') { JSON.parse(@json) }
99
97
  perf.before('JSON::Pure') { JSON.parser = JSON::Pure::Parser }
100
98
  end
101
- unless $failed.has_key?('Oj:wab')
102
- perf.add('Oj:wab', 'wab_load') { Oj.wab_load($json) }
99
+ unless @failed.key?('Oj:wab')
100
+ perf.add('Oj:wab', 'wab_load') { Oj.wab_load(@json) }
103
101
  end
104
- perf.add('Yajl', 'parse') { Yajl::Parser.parse($json) } unless $failed.has_key?('Yajl')
105
- perf.run($iter)
102
+ perf.add('Yajl', 'parse') { Yajl::Parser.parse(@json) } unless @failed.key?('Yajl')
103
+ perf.run(@iter)
106
104
 
107
105
  puts '-' * 80
108
- puts "Wab Dump Performance"
106
+ puts 'Wab Dump Performance'
109
107
  perf = Perf.new()
110
- unless $failed.has_key?('JSON::Ext')
111
- perf.add('JSON::Ext', 'dump') { JSON.generate($obj) }
108
+ unless @failed.key?('JSON::Ext')
109
+ perf.add('JSON::Ext', 'dump') { JSON.generate(@obj) }
112
110
  perf.before('JSON::Ext') { JSON.generator = JSON::Ext::Generator }
113
111
  end
114
- unless $failed.has_key?('JSON::Pure')
115
- perf.add('JSON::Pure', 'generate') { JSON.generate($obj) }
112
+ unless @failed.key?('JSON::Pure')
113
+ perf.add('JSON::Pure', 'generate') { JSON.generate(@obj) }
116
114
  perf.before('JSON::Pure') { JSON.generator = JSON::Pure::Generator }
117
115
  end
118
- unless $failed.has_key?('Oj:wab')
119
- perf.add('Oj:wab', 'dump') { Oj.dump($obj, :mode => :wab) }
116
+ unless @failed.key?('Oj:wab')
117
+ perf.add('Oj:wab', 'dump') { Oj.dump(@obj, :mode => :wab) }
120
118
  end
121
- perf.add('Yajl', 'encode') { Yajl::Encoder.encode($obj) } unless $failed.has_key?('Yajl')
122
- perf.run($iter)
119
+ perf.add('Yajl', 'encode') { Yajl::Encoder.encode(@obj) } unless @failed.key?('Yajl')
120
+ perf.run(@iter)
123
121
 
124
122
  puts
125
123
  puts '-' * 80
126
124
  puts
127
125
 
128
- unless $failed.empty?
129
- puts "The following packages were not included for the reason listed"
130
- $failed.each { |tag,msg| puts "***** #{tag}: #{msg}" }
126
+ unless @failed.empty?
127
+ puts 'The following packages were not included for the reason listed'
128
+ @failed.each { |tag, msg| puts "***** #{tag}: #{msg}" }
131
129
  end
data/test/prec.rb CHANGED
@@ -2,21 +2,21 @@
2
2
 
3
3
  require 'oj'
4
4
 
5
- extras = {"locationLng" => -97.14690769100295}
5
+ extras = { 'locationLng' => -97.14690769100295 }
6
6
 
7
- Oj.default_options = {float_precision: 17}
7
+ Oj.default_options = { float_precision: 17 }
8
8
 
9
9
  encoded = Oj.dump(extras)
10
10
  puts encoded
11
11
  puts Oj.load(encoded)
12
12
 
13
- require "active_record"
13
+ require 'active_record'
14
14
 
15
15
  Oj::Rails.set_encoder()
16
16
  Oj::Rails.set_decoder()
17
17
 
18
- Oj.default_options = {float_precision: 17}
19
- # Using Oj rails encoder, gets the correct value: {"locationLng":-97.14690769100295}
18
+ Oj.default_options = { float_precision: 17 }
19
+ # Using Oj rails encoder, gets the correct value: { 'locationLng':-97.14690769100295 }
20
20
  encoded = ActiveSupport::JSON.encode(extras)
21
21
  puts encoded
22
22
  puts ActiveSupport::JSON.decode(encoded)
@@ -1,4 +1,3 @@
1
-
2
1
  module Sample
3
2
  class Change
4
3
  attr_accessor :time
data/test/sample/dir.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require 'etc'
3
2
 
4
3
  module Sample
data/test/sample/doc.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require 'sample/hasprops'
3
2
  require 'sample/group'
4
3
  require 'sample/layer'
data/test/sample/file.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  require 'etc'
3
2
 
4
3
  module Sample
data/test/sample/group.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Sample
3
2
  class Group
4
3
  attr_reader :members
@@ -1,4 +1,3 @@
1
-
2
1
  module Sample
3
2
  module HasProps
4
3
 
data/test/sample/layer.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Sample
3
2
  class Layer < Group
4
3
  attr_accessor :name
data/test/sample/rect.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Sample
3
2
  class Rect < Shape
4
3
 
data/test/sample/shape.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Sample
3
2
  class Shape
4
3
  include HasProps
data/test/sample/text.rb CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  module Sample
3
2
  class Text < Shape
4
3
  attr_accessor :text
data/test/sample.rb CHANGED
@@ -1,19 +1,19 @@
1
1
  #!/usr/bin/env ruby -wW2
2
+ # frozen_string_literal: true
2
3
 
3
- if $0 == __FILE__
4
- $: << '.'
5
- $: << '..'
6
- $: << '../lib'
7
- $: << '../ext'
4
+ if $PROGRAM_NAME == __FILE__
5
+ $LOAD_PATH << '.'
6
+ $LOAD_PATH << '..'
7
+ $LOAD_PATH << '../lib'
8
+ $LOAD_PATH << '../ext'
8
9
  end
9
10
 
10
- require 'pp'
11
11
  require 'sample/doc'
12
12
 
13
13
  def sample_doc(size=3)
14
14
  colors = [ :black, :gray, :white, :red, :blue, :yellow, :green, :purple, :orange ]
15
15
 
16
- d = ::Sample::Doc.new('Sample')
16
+ d = Sample::Doc.new('Sample')
17
17
 
18
18
  # add some history
19
19
  (0..size * 10).each do |i|
@@ -22,22 +22,22 @@ def sample_doc(size=3)
22
22
 
23
23
  # add some layers
24
24
  (1..size).each do |i|
25
- layer = ::Sample::Layer.new("Layer-#{i}")
25
+ layer = Sample::Layer.new("Layer-#{i}")
26
26
  (1..size).each do |j|
27
- g = ::Sample::Group.new
27
+ g = Sample::Group.new
28
28
  (1..size).each do |k|
29
- g2 = ::Sample::Group.new
30
- r = ::Sample::Rect.new(j * 40 + 10.0, i * 10.0,
31
- 10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
29
+ g2 = Sample::Group.new
30
+ r = Sample::Rect.new((j * 40) + 10.0, i * 10.0,
31
+ 10.123456 / k, 10.0 / k, colors[(i + j + k) % colors.size])
32
32
  r.add_prop(:part_of, layer.name)
33
33
  g2 << r
34
- g2 << ::Sample::Text.new("#{k} in #{j}", r.left, r.top, r.width, r.height)
34
+ g2 << Sample::Text.new("#{k} in #{j}", r.left, r.top, r.width, r.height)
35
35
  g << g2
36
36
  end
37
- g2 = ::Sample::Group.new
37
+ g2 = Sample::Group.new
38
38
  (1..size).each do |k|
39
- o = ::Sample::Oval.new(j * 40 + 12.0, i * 10.0 + 2.0,
40
- 6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
39
+ o = Sample::Oval.new((j * 40) + 12.0, (i * 10.0) + 2.0,
40
+ 6.0 / k, 6.0 / k, colors[(i + j + k) % colors.size])
41
41
  o.add_prop(:inside, true)
42
42
  g << o
43
43
  end
data/test/sample_json.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- if $0 == __FILE__
4
- $: << '.'
5
- $: << '..'
6
- $: << '../lib'
7
- $: << '../ext'
4
+ if $PROGRAM_NAME == __FILE__
5
+ $LOAD_PATH << '.'
6
+ $LOAD_PATH << '..'
7
+ $LOAD_PATH << '../lib'
8
+ $LOAD_PATH << '../ext'
8
9
  end
9
10
 
10
- require 'pp'
11
11
  require 'oj'
12
12
 
13
13
  def sample_json(size=3)
@@ -32,6 +32,6 @@ def sample_json(size=3)
32
32
  container
33
33
  end
34
34
 
35
- if $0 == __FILE__
36
- File.open('sample.json', "w") { |f| f.write(Oj.dump(sample_json(3), :indent => 2)) }
35
+ if $PROGRAM_NAME == __FILE__
36
+ File.write('sample.json', Oj.dump(sample_json(3), :indent => 2))
37
37
  end