I’m confused about how the $ variables work in this part of EventMachine code (strip_op is a String#sub method):
def receive_data(data)
@buf = @buf ? @buf << data : data
while (@buf && !@closing)
case @parse_state
when AWAITING_CONTROL_LINE
case @buf
when PUB_OP
ctrace('PUB OP', strip_op($&)) if NATSD::Server.trace_flag?
return connect_auth_timeout if @auth_pending
@buf = $'
@parse_state = AWAITING_MSG_PAYLOAD
@msg_sub, @msg_reply, @msg_size = $1, $3, $4.to_i
What are the meanings for $&, $', $1, etc.?
Those hold parts of the last regex match.
$&: the matched substring,$': the substring that follows the match,$1: the first captured substring of the match.