Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.ruby > #7220

Re: "Put" in Ruby

Path csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.ruby
Subject Re: "Put" in Ruby
Date Sat, 16 Apr 2016 01:50:12 +0200
Lines 34
Message-ID <dndd1lFd67gU1@mid.individual.net> (permalink)
References <d720c9a9-3943-45d9-83a1-ff3cf224aaef@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net fBOrVsJwmaWEJJSM7Mki8wsW2mvkNF5d5/OX7OXGdmoFgNnzY=
Cancel-Lock sha1:eulmYg4L7le2CQwW0NbXO6dvQ64=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0
In-Reply-To <d720c9a9-3943-45d9-83a1-ff3cf224aaef@googlegroups.com>
Xref csiph.com comp.lang.ruby:7220

Show key headers only | View raw


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/

Back to comp.lang.ruby | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

"Put" in Ruby Cai Gengyang <gengyangcai@gmail.com> - 2016-04-15 08:23 -0700
  Re: "Put" in Ruby Sebastian Christ <rudolfo.christ@gmail.com> - 2016-04-15 20:57 +0200
    Re: "Put" in Ruby Robert Klemme <shortcutter@googlemail.com> - 2016-04-16 01:45 +0200
      Re: "Put" in Ruby Sebastian Christ <rudolfo.christ@gmail.com> - 2016-04-16 11:52 +0200
        Re: "Put" in Ruby Robert Klemme <shortcutter@googlemail.com> - 2016-04-16 13:40 +0200
  Re: "Put" in Ruby Robert Klemme <shortcutter@googlemail.com> - 2016-04-16 01:50 +0200
  Re: "Put" in Ruby Kaz Kylheku <545-066-4921@kylheku.com> - 2016-04-16 01:39 +0000

csiph-web