Class: Rack::Mount::Multimap
- Inherits:
-
NestedMultimap
- Object
- Multimap
- NestedMultimap
- Rack::Mount::Multimap
- Defined in:
- lib/rack/mount/multimap.rb
Overview
:nodoc:
Instance Method Summary collapse
Methods inherited from NestedMultimap
#<<, #[], #containers_with_default, #each_association, #each_container_with_default, #inspect
Methods inherited from Multimap
#==, [], #[], #containers, #delete, #delete_if, #each, #each_association, #each_container, #each_key, #each_pair, #each_value, #eql?, #freeze, #has_value?, #include?, #index, #initialize, #initialize_copy, #invert, #keys, #marshal_dump, #marshal_load, #merge, #reject, #reject!, #replace, #select, #size, #to_a, #to_hash, #to_yaml, #update, #values, #values_at, #yaml_initialize
Constructor Details
This class inherits a constructor from Multimap
Instance Method Details
#average_height ⇒ Object
48 49 50 51 |
# File 'lib/rack/mount/multimap.rb', line 48 def average_height lengths = containers_with_default.map { |e| e.length } lengths.inject(0) { |sum, len| sum += len }.to_f / lengths.size end |
#height ⇒ Object
44 45 46 |
# File 'lib/rack/mount/multimap.rb', line 44 def height containers_with_default.max { |a, b| a.length <=> b.length }.length end |
#store(*args) ⇒ Object Also known as: []=
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/rack/mount/multimap.rb', line 10 def store(*args) keys = args.dup value = keys.pop key = keys.shift raise ArgumentError, 'wrong number of arguments (1 for 2)' unless value unless key.respond_to?(:=~) raise ArgumentError, "unsupported key: #{args.first.inspect}" end if key.is_a?(Regexp) if keys.empty? @hash.each_pair { |k, l| l << value if k =~ key } self.default << value else @hash.each_pair { |k, _| if k =~ key args[0] = k super(*args) end } self.default = self.class.new(default) unless default.is_a?(self.class) default[*keys.dup] = value end else super(*args) end end |