Sha256: 9ffe3060f8040b2f5d84d03e56a0ab3f5b75ddcef45a4f1f6e88d0d48683ac01

Contents?: true

Size: 517 Bytes

Versions: 6

Compression:

Stored size: 517 Bytes

Contents

require 'set'

# This is a hack that I don't want to ever use anywhere else or repeat EVER, but we need enums to be
# an Array to pass schema validation. But we also want fast lookup!

class ArraySet < Array
  def include?(obj)
    if !defined? @values
      @values = Set.new
      self.each { |x| @values << convert_to_float_if_fixnum(x) }
    end
    @values.include?(convert_to_float_if_fixnum(obj))
  end

  private

  def convert_to_float_if_fixnum(value)
    value.is_a?(Fixnum) ? value.to_f : value
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
json-schema-2.7.0 lib/json-schema/util/array_set.rb
json-schema-2.6.2 lib/json-schema/util/array_set.rb
json-schema-2.6.1 lib/json-schema/util/array_set.rb
json-schema-2.6.0 lib/json-schema/util/array_set.rb
json-schema-2.5.2 lib/json-schema/util/array_set.rb
json-schema-2.5.1 lib/json-schema/util/array_set.rb