Reputation: 93306
im new to ruby and rails.
in RoR3 a controller inherits from the ActionController::Base
request.env["SERVER_ADDR"]
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!
Upvotes: 1
Views: 207
Reputation: 369624
request.env["SERVER_ADDR"]
request
is either
a. dereferencing the local variable request
or
b. sending the message :request
with no arguments to the implicit receiver self
,
env
is sending the message :env
with no arguments to the object obtained by dereferencing request
or the object returned in response to sending the message :request
to self
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")
Upvotes: 1
Reputation: 370465
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"
.
Upvotes: 1