Method: NoSE::KeyPath#+

Defined in:
lib/nose/statements.rb

#+(other) ⇒ KeyPath

Combine two key paths by gluing together the keys

Returns:



149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/nose/statements.rb', line 149

def +(other)
  fail TypeError unless other.is_a? KeyPath
  other_keys = other.instance_variable_get(:@keys)

  # Just copy if there's no combining necessary
  return dup if other_keys.empty?
  return other.dup if @keys.empty?

  # Only allow combining if the entities match
  fail ArgumentError unless other_keys.first.parent == entities.last

  # Combine the two paths
  KeyPath.new(@keys + other_keys[1..-1])
end