Skip to content

Commit

Permalink
Defined #<< instead of alias for overriding purposes (#6).
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzedge committed Jul 21, 2012
1 parent 6a91f1e commit 0612b18
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lib/rambling-trie/branches.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ module Rambling
module Trie
# Provides the branching behavior for the Trie data structure.
module Branches
# Adds a branch to the trie based on the word.
# Adds a branch to the current trie node based on the word
# @param [String] word the word to add the branch from.
# @return [Node] the just added branch's root node.
# @raise [InvalidOperation] if the trie is already compressed.
# @note This method clears the contents of the word variable.
def add_branch_from(word)
raise InvalidOperation.new('Cannot add branch to compressed trie') if compressed?
if word.empty?
Expand All @@ -25,7 +26,14 @@ def add_branch_from(word)
end
end

alias_method :<<, :add_branch_from
# Alias for {#add_branch_from}. Defined instead of simple `alias_method` for overriding purposes.
# @param [String] word the word to add the branch from.
# @return [Node] the just added branch's root node.
# @raise [InvalidOperation] if the trie is already compressed.
# @see #add_branch_from
def <<(word)
add_branch_from word
end

protected

Expand Down

0 comments on commit 0612b18

Please sign in to comment.