lib/ordered_list/position/intermediable.rb
def between(other)
        # Guarantee that self is the shorter position of the two.
        return other.between(self) if length > other.length

        # Find common ancestor of both positions.
        short, long = to_enum, other.to_enum
        intermediate = ancestor_of_enums(short, long)

        # Stop and return common ancestor if both paths have more digits.
        return intermediate unless enum_end?(short)

        # Raise error if neither paths have more digits -- they are equal.
        raise EqualPositions, "Cannot create intermediate between equal positions" if enum_end?(long)

        # Check the direction of the longest path after the split from the
        # common ancestor.
        intermediate << (direction = long.next)

        # Append digits of longest path until direction changes.
        loop do
          break if long.peek == direction
          intermediate << long.next
        end

        # If we're at the end of the path, append opposite of initial
        # direction to create a new child.
        intermediate << (1 ^ direction) if enum_end?(long)

        # Return the new intermediate position.
        intermediate
      end
# Calculates a new position between this position and the given other
# position. The intermediate position may either be a common ancestor,
# or an ancestor of one and a descendant of the other, or a child of one
# and a descendant of the other. The new position is the shortest one
# possible between the two positions (without renumbering). An
# EqualPositions exception is raised if the two positions are equal.
Calculates a new position between this position and the given other
position. The intermediate position may either be a common ancestor,
or an ancestor of one and a descendant of the other, or a child of one
and a descendant of the other. The new position is the shortest one
possible between the two positions (without renumbering). An
EqualPositions exception is raised if the two positions are equal.
Calculates a new position between this position and the given other position . The intermediate position may either be a common ancestor or an ancestor of one and a descendant of the other or a child of one and a descendant of the other . The new position is the shortest one possible between the two positions ( without renumbering ) . An EqualPositions exception is raised if the two positions are equal .
def between(other)
        return other.between(self) if length > other.length
        short, long = to_enum, other.to_enum
        intermediate = ancestor_of_enums(short, long)
        return intermediate unless enum_end?(short)
        raise EqualPositions, "Cannot create intermediate between equal positions" if enum_end?(long)
        intermediate << (direction = long.next)
        loop do
          break if long.peek == direction
          intermediate << long.next
        end
        intermediate << (1 ^ direction) if enum_end?(long)
        intermediate
      end
def between ( other ) return other . between ( self ) if length > other . length short , long = to_enum , other . to_enum intermediate = ancestor_of_enums ( short , long ) return intermediate unless enum_end? ( short ) raise EqualPositions , "Cannot create intermediate between equal positions" if enum_end? ( long ) intermediate << ( direction = long . next ) loop do break if long . peek == direction intermediate << long . next end intermediate << ( 1 ^ direction ) if enum_end? ( long ) intermediate end
Calculates a new position between this position and the given other
position.
Calculates a new position between this position and the given other position .
# Guarantee that self is the shorter position of the two. # Find common ancestor of both positions. # Stop and return common ancestor if both paths have more digits. # Raise error if neither paths have more digits -- they are equal. # Check the direction of the longest path after the split from the # common ancestor. # Append digits of longest path until direction changes. # If we're at the end of the path, append opposite of initial # direction to create a new child. # Return the new intermediate position.
other