Ruby has implicit returns, so it's the value of whatever the last evaluated
expression is. In this case, it'll be the return value of the last system
call.
···
On Sat, Oct 3, 2015 at 9:30 AM, Sascha Manns <Sascha.Manns@directbox.com> wrote:
Hello list,
because i'm trying to make my code documentation better, i would like to
know a thing.
I have that method:
def self.my_method
system('xelatex cv_10.tex')
system('biber cv_10.bcf')
system('xelatex cv_10.tex')
end
What returns a method in the case (like that) that aren't defined a
returning value.
I'm not quite sure what you're trying to ask. Do you mean, "what does
a method return, if it doesn't use the 'return' keyword"? ("Returning
a method" is also possible, but a very advanced topic.)
It returns the value of its last expression evaluated. The "return"
keyword is optional in these cases, and rarely used. So, for
instance:
def add(a, b)
puts "Adding #{a} and #{b}"
a + b
end
is the same as:
def add(a, b)
puts "Adding #{a} and #{b}"
return a + b
end
and would have the same result (though different printed output) as:
def add(a, b)
c = a + b
puts "Adding #{a} and #{b}; got #{c}"
c # we could also do "return c" here
end
-Dave
···
On Sat, Oct 3, 2015 at 9:30 AM, Sascha Manns <Sascha.Manns@directbox.com> wrote:
What returns a method in the case (like that) that aren't defined a
returning value.
--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.
Ammendind the others. ...
To know what Kernel#system returns (as it is the last expression of your
method) look at Module: Kernel (Ruby 2.2.0)
···
Em Sáb, 3 de out de 2015 10:49, Dave Aronson < ruby-talk.list.2.TRex@codosaur.us> escreveu:
On Sat, Oct 3, 2015 at 9:30 AM, Sascha Manns <Sascha.Manns@directbox.com> > wrote:
> What returns a method in the case (like that) that aren't defined a
> returning value.
I'm not quite sure what you're trying to ask. Do you mean, "what does
a method return, if it doesn't use the 'return' keyword"? ("Returning
a method" is also possible, but a very advanced topic.)
It returns the value of its last expression evaluated. The "return"
keyword is optional in these cases, and rarely used. So, for
instance:
def add(a, b)
puts "Adding #{a} and #{b}"
a + b
end
is the same as:
def add(a, b)
puts "Adding #{a} and #{b}"
return a + b
end
and would have the same result (though different printed output) as:
def add(a, b)
c = a + b
puts "Adding #{a} and #{b}; got #{c}"
c # we could also do "return c" here
end
-Dave
--
Dave Aronson, consulting software developer of Codosaur.us,
PullRequestRoulette.com, Blog.Codosaur.us, and Dare2XL.com.
System method returns 0 or not (in the case if there' re errors or not).
But if you received that there're not errors in system call, there're not
any guaranties that system processed your shell command successfully.
thank you very much for helping me to clarify that point. Now i can
write better code documentations
Greetings
Sascha
···
Am 04.10.2015 um 11:57 schrieb Alexey Bovanenko:
System method returns 0 or not (in the case if there' re errors or
not). But if you received that there're not errors in system call,
there're not any guaranties that system processed your shell command
successfully.
Perhaps you've mistaken the return values of Kernel#system.
system 'ls'
=> true
system 'ls non-existent-file' # It would give an error from the 'ls' itself
ls: non-existent-file: No such file or directory
=> false
system 'nonexistentshellcommand' # It would give an error from the shell
=> nil
Look, true, false and nil. Those are the returning values of system.
(No 0 (zero) returned).
Abinoam Jr.
···
On Sun, Oct 4, 2015 at 9:41 AM, Sascha Manns <Sascha.Manns@directbox.com> wrote:
Hello Alexey and all others,
thank you very much for helping me to clarify that point. Now i can write
better code documentations
Greetings
Sascha
Am 04.10.2015 um 11:57 schrieb Alexey Bovanenko:
System method returns 0 or not (in the case if there' re errors or not). But
if you received that there're not errors in system call, there're not any
guaranties that system processed your shell command successfully.