Skip to content

Commit

Permalink
Change case statement to be a Hash lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
dkubb committed Dec 14, 2013
1 parent 101e358 commit 6744cab
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/adamantium/freezer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ class UnknownFreezerError < RuntimeError; end
# Error raised when memoizer options contain unknown keys
class OptionError < RuntimeError; end

@freezers = {
noop: Noop,
deep: Deep,
flat: Flat,
}.freeze

# Return freezer for name
#
# @param [Symbol] name
Expand All @@ -103,11 +109,7 @@ class OptionError < RuntimeError; end
#
# @api private
def self.get(name)
case name
when :noop then Noop
when :deep then Deep
when :flat then Flat
else
@freezers.fetch(name) do
fail UnknownFreezerError, "Freezer with name #{name.inspect} is unknown"
end
end
Expand Down

0 comments on commit 6744cab

Please sign in to comment.