Class: Rack::Mount::GeneratableRegexp::DynamicSegment

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/mount/generatable_regexp.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, requirement) ⇒ DynamicSegment

Returns a new instance of DynamicSegment.



8
9
10
11
# File 'lib/rack/mount/generatable_regexp.rb', line 8

def initialize(name, requirement)
  @name, @requirement = name.to_sym, requirement
  freeze
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rack/mount/generatable_regexp.rb', line 6

def name
  @name
end

#requirementObject (readonly)

Returns the value of attribute requirement.



6
7
8
# File 'lib/rack/mount/generatable_regexp.rb', line 6

def requirement
  @requirement
end

Instance Method Details

#==(obj) ⇒ Object



13
14
15
# File 'lib/rack/mount/generatable_regexp.rb', line 13

def ==(obj)
  @name == obj.name && @requirement == obj.requirement
end

#=~(str) ⇒ Object



17
18
19
# File 'lib/rack/mount/generatable_regexp.rb', line 17

def =~(str)
  @requirement =~ str
end

#inspectObject



25
26
27
# File 'lib/rack/mount/generatable_regexp.rb', line 25

def inspect
  "/(?<#{@name}>#{@requirement.source})/"
end

#to_hashObject



21
22
23
# File 'lib/rack/mount/generatable_regexp.rb', line 21

def to_hash
  { @name => @requirement }
end