Можно использовать #send метод для называния метода объекта именем метода:
object.send(:foo) # same as object.foo
можно передать споры с вызываемому методу:
object.send(:foo, 1, "bar", 1.23) # same as object.foo(1, "bar", 1.23)
Так, если у Вас есть название атрибута в переменном "атрибуте", можно считать атрибут объекта с [1 110]
object.send(attribute.to_sym)
и записать значение атрибута с [1 111]
object.send("#{attribute}=".to_sym, value)
В Ruby, 1.8.6 #send методов могут выполнить метод любого объекта независимо от своей видимости (Вы можете, например, называть закрытые методы). Это подвержено изменениям в будущих версиях Ruby, и Вы не должны полагаться на него. Для выполнения закрытых методов используйте #instance_eval:
object.instance_eval {
# code as block, can reference variables in current scope
}
# or
object.instance_eval <<-CODE
# code as string, can generate any code text
CODE
можно использовать public_send
для вызова методов относительно правил видимости.
object.public_send :public_foo # ok
object.public_send :private_bar # exception
To achieve #2 you can manually check the cookie and its AuthenticationTicket for expiration and redirect to your custom page if they have expired.
You can do in it in one of the events: AcquireRequestState, AuthenticateRequest.
Sample code in the event can look like:
// Retrieve AuthenticationCookie
var cookie = Request.Cookies[FormsAuthentication.FormsCookieName];
if (cookie == null) return;
FormsAuthenticationTicket ticket = null;
try {
ticket = FormsAuthentication.Decrypt(cookie.Value);
} catch (Exception decryptError) {
// Handle properly
}
if (ticket == null) return; // Not authorised
if (ticket.Expiration > DateTime.Now) {
Response.Redirect("SessionExpiredPage.aspx"); // Or do other stuff here
}