Sha256: 2291a2746ac8910becabb13ed2ea453824717c94e3b121d660f1a51b2dc6408a

Contents?: true

Size: 819 Bytes

Versions: 14

Compression:

Stored size: 819 Bytes

Contents

module MultiJson
  module Options
    attr_writer :load_options, :dump_options

    def load_options(*args)
      get_options :load_options, *args
    end

    def dump_options(*args)
      get_options :dump_options, *args
    end

    def default_load_options
      @default_load_options ||= {}
    end

    def default_dump_options
      @default_dump_options ||= {}
    end

    private

    def get_options(ivar, *args)
      defaults = send("default_#{ivar}")

      return defaults unless instance_variable_defined?("@#{ivar}")

      value = instance_variable_get("@#{ivar}")

      if value.respond_to?(:call) and value.arity
        value.arity == 0 ? value[] : value[*args]
      elsif Hash === value or value.respond_to?(:to_hash)
        value.to_hash
      else
        defaults
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 5 rubygems

Version Path
font-awesome-rails-3.1.1.2 vendor/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/options.rb
vagrant-shell-0.2.6 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/options.rb
font-awesome-rails-3.1.1.1 vendor/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/options.rb
challah-1.0.0.beta3 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/options.rb
vagrant-shell-0.2.5 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/options.rb
fc-webicons-0.0.4 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/options.rb
challah-1.0.0.beta2 vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/options.rb
challah-1.0.0.beta vendor/bundle/gems/multi_json-1.7.2/lib/multi_json/options.rb
fc-webicons-0.0.3 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/options.rb
fc-webicons-0.0.2 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/options.rb
fc-webicons-0.0.1 vendor/bundle/ruby/1.9.1/gems/multi_json-1.7.2/lib/multi_json/options.rb
multi_json-1.7.2 lib/multi_json/options.rb
multi_json-1.7.1 lib/multi_json/options.rb
multi_json-1.7.0 lib/multi_json/options.rb