class declaration for ruby
im new to ruby and rails.
in RoR3 a controller inherits from the ActionController::Base
request.env["SERVER_ADDR"开发者_JAVA百科]
so request is a method in Base class (that is inside the ActionController module)?
what is env
then and ["SERVER_ADDR"]
?
would be great if someone could make a little code example...that would be very helpful to understand!
thanks!
request.env["SERVER_ADDR"]
request
is eithera. dereferencing the local variable
request
orb. sending the message
:request
with no arguments to the implicit receiverself
,env
is sending the message:env
with no arguments to the object obtained by dereferencingrequest
or the object returned in response to sending the message:request
toself
in step 2,["SERVER_ADDR"]
is sending the message:[]
with the argument"SERVER_ADDR"
to the object returned in response to sending the message:env
in step 2 and"SERVER_ADDR"
is a string literal.
You could more explicitly write it like this:
self.request.env.[]("SERVER_ADDR")
or even more explicit like this:
self.request().env().[]("SERVER_ADDR")
and even full out:
self.send(:request).send(:env).send(:[], "SERVER_ADDR")
request.env["SERVER_ADDR"]
can also be written as request().env()["SERVER_ADDR"]
. So env
is a method that is called without arguments on the object returned by request()
and then you call []
on the object returned by that with the argument "SERVER_ADDR"
.
精彩评论