Sha256: 49a6e4fbdf9401b72b42f2eb932abf18eff358c725b885110d7b14c45620a663

Contents?: true

Size: 792 Bytes

Versions: 4

Compression:

Stored size: 792 Bytes

Contents

class Array
  def deconstruct
    self
  end
end

class Hash
  def deconstruct_keys(_)
    self
  end
end

class Struct
  alias deconstruct to_a
  # This function is specified in a very weird way...
  def deconstruct_keys(keys)
    return to_h if keys.nil?
    raise TypeError, 'expected Array or nil' unless Array === keys
    return {} if keys.length > values.length
    out = {}
    keys.each do |key|
      should_break = case key
                     when Integer
                       values.length < key
                     when Symbol # Or String? Doesn't matter, we're in Opal.
                       !members.include?(key)
                     end
      break if should_break
      out[key] = self[key]
    end
    out
  end
end

class NoMatchingPatternError < StandardError; end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
opal-1.3.2 opal/corelib/pattern_matching/base.rb
opal-1.3.1 opal/corelib/pattern_matching/base.rb
opal-1.3.0 opal/corelib/pattern_matching/base.rb
opal-1.3.0.rc1 opal/corelib/pattern_matching/base.rb