On 15.04.2016 17:23, Cai Gengyang wrote:
First off, puts is not a function. It's sole purpose is to have a
side-effect (printing something to the console), whereas functions
cannot have side-effects ... that's the definition of "function",
after all.
More precisely this is _one_ definition of function. Other context are
more liberal and will include functions with side effects.
Ruby doesn't have functions. It only has methods. Thus, puts is a
method.
Is this true ?
If you apply a strict definition, yes. Every method can have side
effects - but it does not need to. There is no way to declare a "thing"
in Ruby to be a function without side effects.
So basically, 'puts' is just a "thing" to enable
printing something to the console ...
It is a method with the side effect of writing a character
representation of its arguments to whatever file descriptor 0 (usually
called "stdout") points to. Additionally there are some formatting
tricks, i.e. newlines will be inserted between output of arguments.
Kind regards
robert
--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)