开发者

class declaration for ruby

开发者 https://www.devze.com 2023-01-06 22:25 出处:网络
im new to ruby and rails. in RoR3 a controller inherits from the ActionController::Base request.env[\"SERVER_ADDR\"开发者_JAVA百科]

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"]
  1. request is either

    a. dereferencing the local variable request or

    b. sending the message :request with no arguments to the implicit receiver self,

  2. 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,
  3. ["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
  4. "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".

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号