Skip to content

Commit

Permalink
Templates should be freezable.
Browse files Browse the repository at this point in the history
  • Loading branch information
sporkmonger committed Mar 29, 2015
1 parent 3a1d473 commit 5446003
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion lib/addressable/template.rb
Expand Up @@ -237,6 +237,17 @@ def initialize(pattern)
@pattern = pattern.to_str.freeze
end

##
# Freeze URI, initializing instance variables.
#
# @return [Addressable::URI] The frozen URI object.
def freeze
self.variables
self.variable_defaults
self.named_captures
super
end

##
# @return [String] The Template object's pattern.
attr_reader :pattern
Expand Down Expand Up @@ -616,7 +627,9 @@ def variable_defaults
# that in conjunction with this method, but I'm reluctant to raise an
# exception in that scenario right now.
def named_captures
Hash[self.variables.zip((1..self.variables.length).map { |i| Array(i) })]
@named_captures ||= Hash[
self.variables.zip((1..self.variables.length).map { |i| Array(i) })
]
end

private
Expand Down

0 comments on commit 5446003

Please sign in to comment.