lloyd / yajl

A fast streaming JSON parsing library in C.
http://lloyd.github.com/yajl
ISC License
2.15k stars 435 forks source link

yajl.rb - (# TODO: this code smells, any ideas?) - "ArgumentError" #237

Open ghost opened 2 years ago

ghost commented 2 years ago

Please clarify - can we trust this code in yajl-ruby gem yajl.rb file? (# TODO: this code smells, any ideas?)

class Encoder def self.encode(obj, args, &block)

TODO: this code smells, any ideas?

args.flatten! options = {} io = nil args.each do |arg| if arg.is_a?(Hash) options = arg elsif arg.respond_to?(:write) io = arg end end if args.any? new(options).encode(obj, io, &block) end end end

========= it generates following error:

2022-01-21 12:26:09 -0500 [warn]: fluent/root_agent.rb:187:emit_error_event: dump an error event: error_class=ArgumentError error="wrong number of arguments (1 for 0)" location="/opt/csw/lib/ruby/gems/2.0.0/gems/yajl-ruby-1.4.1/lib/yajl.rb:80:in initialize'" tag="fluent.warn" time=1642785969 record={"error_class"=>"ArgumentError", "error"=>"wrong number of arguments (1 for 0)", "location"=>"/opt/csw/lib/ruby/gems/2.0.0/gems/yajl-ruby-1.4.1/lib/yajl.rb:80:ininitialize'", "tag"=>"fluent.debug", "time"=>1642785969, "record"=>{"message"=>"fluentd main process get SIGINT", "@timestamp"=>"2022-01-21T12:26:09-05:00"}, "message"=>"dump an error event: error_class=ArgumentError error="wrong number of arguments (1 for 0)" location="/opt/csw/lib/ruby/gems/2.0.0/gems/yajl-ruby-1.4.1/lib/yajl.rb:80:in `initialize'" tag="fluent.debug" time=1642785969 record={"message"=>"fluentd main process get SIGINT", "@timestamp"=>"2022-01-21T12:26:09-05:00"}", "@timestamp"=>"2022-01-21T12:26:09-05:00"}