Skip to content

Commit

Permalink
Refactor MultiJson::Options#get_options
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Mar 14, 2024
1 parent 81f0ffc commit 817480d
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/multi_json/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ def default_dump_options
private

def get_options(options, *args)
if options.respond_to?(:call) && options.arity
options.arity.zero? ? options[] : options[*args]
elsif options.respond_to?(:to_hash)
options.to_hash
end
return handle_callable_options(options, *args) if options_responds_to_call?(options)

handle_hashable_options(options)
end

def options_responds_to_call?(options)
options.respond_to?(:call)
end

def handle_callable_options(options, *args)
options.arity.zero? ? options[] : options[*args]
end

def handle_hashable_options(options)
options.respond_to?(:to_hash) ? options.to_hash : nil
end
end
end

0 comments on commit 817480d

Please sign in to comment.