This is a total newbie question, but I'd like to know how "return" is
specifically used in ruby. From my understanding, it can be avoided in a
lot of cases since ruby returns the last value by default.
However, some of the code in the Rails stuff I'm looking at has "return" and
I was wondering if this "return" is necessary or just the individual
programmer's style (maybe carried over from other languages).
Sorry, I'm vague but I would like to know how "return" is effectively used
in ruby if at all.
Here's a code snippet from the SaltedHash Engine
def new_security_token(hours = nil)
write_attribute('security_token', AuthenticatedUser.hashed(
self.salted_password + Time.now.to_i.to_s + rand.to_s))
write_attribute('token_expiry', Time.at(Time.now.to_i +
token_lifetime(hours)))
update_without_callbacks
return self.security_token
end
or this:
def authenticate(login, pass)
u = find(:first, :conditions => ["login = ? AND verified = 1 AND
deleted = 0", login])
return nil if u.nil?
find(:first, :conditions => ["login = ? AND salted_password = ? AND
verified = 1", login, AuthenticatedUser.salted_password(u.salt,
AuthenticatedUser.hashed(pass))])
end
Sorry if my question's off the wall. Still finding my bearings.