1
我感到困惑的$
變量的EventMachine的這部分代碼是如何工作的(strip_op
是String#sub
方法):
def receive_data(data)
@buf = @buf ? @buf << data : data
while (@buf && [email protected])
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
有哪些含義$&
,$'
,$1
等?
看到這個:http://jimneath.org/2010/01/04/cryptic-ruby-global-variables-and-their-meanings.html –
這些都記錄在這裏和那裏的互聯網周圍,但他們的形式使很難搜索。檢查「[魔術$前綴在Ruby中的變量;是否有一個完整的參考?](http://stackoverflow.com/questions/3746615/magic-prefixed-variables-in-ruby-is-there-a-complete-參考 - 某處)「和http://www.cs.auckland.ac.nz/references/ruby/stdlib/libdoc/English/rdoc/index.html –