Limits the number of formats that we memoize to prevent unbounded memory consumption.
Memoizes the set of emitter objects for the given example in order to improve performance.
# File lib/stamp.rb, line 38 def memoize_stamp_emitters(example) @@memoized_stamp_emitters ||= {} @@memoized_stamp_emitters.clear if @@memoized_stamp_emitters.size > MEMOIZATION_CAP @@memoized_stamp_emitters[example] ||= stamp_emitters(example) end
Formats a date/time using a human-friendly example as a template.
@param [String] example a human-friendly date/time example @param [Hash] options @option options [Boolean] :memoize (true)
@return [String] the formatted date or time
@example
Date.new(2012, 12, 21).stamp("Jan 1, 1999") #=> "Dec 21, 2012"
# File lib/stamp.rb, line 30 def stamp(example) memoize_stamp_emitters(example).format(self) end
Generated with the Darkfish Rdoc Generator 2.