All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gems.multi_json-1.11.0.lib.multi_json.options.rb Maven / Gradle / Ivy

There is a newer version: 3.7.2
Show newest version
module MultiJson
  module Options

    def load_options=(options)
      @load_options = options
    end

    def dump_options=(options)
      @dump_options = options
    end

    def load_options(*args)
      defined?(@load_options) && get_options(@load_options, *args) || default_load_options
    end

    def dump_options(*args)
      defined?(@dump_options) && get_options(@dump_options, *args) || default_dump_options
    end

    def default_load_options
      @default_load_options ||= {}
    end

    def default_dump_options
      @default_dump_options ||= {}
    end

    private

    def get_options(options, *args)
      if options.respond_to?(:call) and options.arity
        options.arity == 0 ? options[] : options[*args]
      elsif Hash === options or options.respond_to?(:to_hash)
        options.to_hash
      end
    end
  end
end




© 2015 - 2025 Weber Informatics LLC | Privacy Policy