From: Tito Ciuro Date: 2007-10-20T00:30:19+09:00 Subject: Re: Is it always the norm to skip 'return'? --Apple-Mail-3--247746401 Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Hi Glen, On Oct 19, 2007, at 8:22 AM, Glen Holcomb wrote: > On 10/19/07, Tito Ciuro wrote: >> >> Hello, >> >> I have a question about skipping the 'return' keyword in a Ruby >> method. >> For example: >> >> def self.encrypted_password(password, salt) >> string_to_hash = password + salt >> Digest::SHA1.hexdigest(string_to_hash) >> end >> >> Being used to work in other languages, this is weird to me. Without >> looking at the documentation, I have no way of knowing that >> 'hexdigest' >> returns a string. Wouldn't the following be easier to understand?: >> >> def self.encrypted_password(password, salt) >> string_to_hash = password + salt >> return Digest::SHA1.hexdigest(string_to_hash) >> end >> >> Why so many Ruby snippets skip the 'return' keyword? >> >> Thanks, >> >> -- Tito >> -- >> Posted via http://www.ruby-forum.com/. >> >> > Because Ruby lets you be lazy like that. You can put it in if you > want but > you don't have to so laziness prevails. > > However how does your adding return address your issue with not > knowing what > the last method call returns? Well, if I'm looking at some code with a return statement as shown above, I tells me that Digest::SHA1.hexdigest returns a string, which in turn the method returns as well. I don't really need to check the documentation. I just think that in this case it pays off to be a little less lazy :-) Thanks for your reply. -- Tito --Apple-Mail-3--247746401--