Class: Peruby::MatchState
- Inherits:
-
Object
- Object
- Peruby::MatchState
- Defined in:
- lib/peruby/runtime/match_state.rb
Overview
Dynamic values exposed by Perl's most recent successful regexp match.
Instance Attribute Summary collapse
-
#md ⇒ Object
readonly
Returns the value of attribute md.
-
#subject ⇒ Object
readonly
Returns the value of attribute subject.
Instance Method Summary collapse
- #fetch(sigil, name) ⇒ Object
-
#initialize(match_data = nil, subject = '') ⇒ MatchState
constructor
A new instance of MatchState.
Constructor Details
#initialize(match_data = nil, subject = '') ⇒ MatchState
Returns a new instance of MatchState.
8 9 10 11 |
# File 'lib/peruby/runtime/match_state.rb', line 8 def initialize(match_data = nil, subject = '') @md = match_data @subject = subject end |
Instance Attribute Details
#md ⇒ Object (readonly)
Returns the value of attribute md.
6 7 8 |
# File 'lib/peruby/runtime/match_state.rb', line 6 def md @md end |
#subject ⇒ Object (readonly)
Returns the value of attribute subject.
6 7 8 |
# File 'lib/peruby/runtime/match_state.rb', line 6 def subject @subject end |
Instance Method Details
#fetch(sigil, name) ⇒ Object
13 14 15 16 17 18 19 20 |
# File 'lib/peruby/runtime/match_state.rb', line 13 def fetch(sigil, name) return nil unless @md return scalar(name) if sigil == :scalar && name.match?(/\A(?:\d+|[&`'+])\z/) return offsets(name) if sigil == :array && %w[- +].include?(name) return named(name) if sigil == :hash && %w[- +].include?(name) nil end |