Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #7217
| Newsgroups | comp.lang.ruby |
|---|---|
| Date | 2016-04-15 08:23 -0700 |
| Message-ID | <d720c9a9-3943-45d9-83a1-ff3cf224aaef@googlegroups.com> (permalink) |
| Subject | "Put" in Ruby |
| From | Cai Gengyang <gengyangcai@gmail.com> |
An examination of "Put" in Ruby :
# this one is like your scripts with ARGV
def print_two(*args)
arg1, arg2 = args
puts "arg1: #{arg1}, arg2: #{arg2}"
end
# ok, that *args is actually pointless, we can just do this
def print_two_again(arg1, arg2)
puts "arg1: #{arg1}, arg2: #{arg2}"
end
# this just takes one argument
def print_one(arg1)
puts "arg1: #{arg1}"
end
# this one takes no arguments
def print_none()
puts "I got nothin'."
end
print_two("Zed","Shaw")
print_two_again("Zed","Shaw")
print_one("First!")
print_none()
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.
Ruby doesn't have functions. It only has methods. Thus, puts is a method.
Is this true ? So basically, 'puts' is just a "thing" to enable printing something to the console ...
Back to comp.lang.ruby | Previous | Next — Next in thread | Find similar
"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