Class: SimpleArgs::Match

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_args/match.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#matchdataObject (readonly)

Returns the value of attribute matchdata.



6
7
8
# File 'lib/simple_args/match.rb', line 6

def matchdata
  @matchdata
end

Class Method Details

.match(rgx, subject) ⇒ Object



8
9
10
11
# File 'lib/simple_args/match.rb', line 8

def match(rgx, subject)
  m = rgx.match(subject)
  return new(m) if m
end

Instance Method Details

#capturesObject



14
# File 'lib/simple_args/match.rb', line 14

def captures = matchdata.captures

#deconstructObject



19
# File 'lib/simple_args/match.rb', line 19

def deconstruct(*) = to_a

#deconstruct_keysObject



20
21
22
23
24
25
26
# File 'lib/simple_args/match.rb', line 20

def deconstruct_keys(*)
  named_captures
    .compact
    .inject({}) do |h, (k, v)|
      h.merge( k.to_sym => v )
    end
end

#named_capturesObject



15
# File 'lib/simple_args/match.rb', line 15

def named_captures = matchdata.named_captures

#to_aObject



16
# File 'lib/simple_args/match.rb', line 16

def to_a = matchdata.to_a

#to_sObject



17
# File 'lib/simple_args/match.rb', line 17

def to_s = matchdata.to_s