lib/citrus.rb in citrus-3.0.0 vs lib/citrus.rb in citrus-3.0.1
- old
+ new
@@ -1324,37 +1324,28 @@
@string ||= input.to_str[offset, length]
end
# Returns a hash of capture names to arrays of matches with that name,
# in the order they appeared in the input.
- def captures
+ def captures(name = nil)
process_events! unless @captures
- @captures
+ name ? @captures[name] : @captures
end
+ # Convenient method for captures[name].first.
+ def capture(name)
+ captures[name].first
+ end
+
# Returns an array of all immediate submatches of this match.
def matches
process_events! unless @matches
@matches
end
# A shortcut for retrieving the first immediate submatch of this match.
def first
matches.first
- end
-
- # Allows methods of this match's string to be called directly and provides
- # a convenient interface for retrieving the first match with a given name.
- def method_missing(sym, *args, &block)
- unless defined?(Citrus::METHOD_MISSING_WARNED)
- warn("[`#{sym}`] Citrus::Match#method_missing is unsafe and will be removed in 3.0. Use captures.")
- Citrus.send(:const_set, :METHOD_MISSING_WARNED, true)
- end
- if string.respond_to?(sym)
- string.__send__(sym, *args, &block)
- else
- captures[sym].first
- end
end
alias_method :to_s, :string
# This alias allows strings to be compared to the string value of Match