Yes… actually I guess you’d have to default it to
nil if you actually wanted it to accept NO ARGUMENT
passed in: def foo(foobar=nil)
Just to emphasise the point. If you call your code with no
argument, the parser or whever you call it will spit the dummy. Just
as zero is a number, nil qualifies as an argument.
I’d effectively get a ‘array index out of bounds’ error or something
yeah?
Try it and see (that’s what irb is for):
def foo(foobar)
puts (foobar || 9)
end
=> nil
foo
ArgumentError: wrong # of arguments(0 for 1)
from (irb):7:in `foo’
from (irb):7
foo(nil)
9
=> nil
foo(“son of a gun”)
son of a gun
=> nil
If you haven’t used irb before, get used to it! It was invoked with
–simple-prompt above (why isn’t there a short command for that?).
The “nil” after each method invocation are the return value of the
method, which is the r/v of puts, which is always nil. When mucking
around in irb, there’s no need to use puts in examples like the above,
e.g.
def foo(foobar)
foobar || 9
end
=> nil
foo
ArgumentError: wrong # of arguments(0 for 1)
from (irb):4:in `foo’
from (irb):4
foo(nil)
=> 9
foo(“sun of a gun”)
=> “sun of a gun”
irb is too useful to ignore.
Gavin
···
On Tuesday, January 21, 2003, 11:03:25 AM, Dmitri wrote:
Thanks for that. I have been pointed toward irb a couple of times, but
I really need to get use to using it for this sort of thing. thanks for
the pointer.
cheers
dim
Gavin Sinclair wrote:
···
On Tuesday, January 21, 2003, 11:03:25 AM, Dmitri wrote:
Gavin Sinclair wrote:
Yes… actually I guess you’d have to default it to
nil if you actually wanted it to accept NO ARGUMENT
passed in: def foo(foobar=nil)
Just to emphasise the point. If you call your code with no
argument, the parser or whever you call it will spit the dummy. Just
as zero is a number, nil qualifies as an argument.
I’d effectively get a ‘array index out of bounds’ error or something
yeah?
Try it and see (that’s what irb is for):
def foo(foobar)
puts (foobar || 9)
end
=> nil
foo
ArgumentError: wrong # of arguments(0 for 1)
from (irb):7:in `foo’
from (irb):7
foo(nil)
9
=> nil
foo(“son of a gun”)
son of a gun
=> nil
If you haven’t used irb before, get used to it! It was invoked with
–simple-prompt above (why isn’t there a short command for that?).
The “nil” after each method invocation are the return value of the
method, which is the r/v of puts, which is always nil. When mucking
around in irb, there’s no need to use puts in examples like the above,
e.g.
def foo(foobar)
foobar || 9
end
=> nil
foo
ArgumentError: wrong # of arguments(0 for 1)
from (irb):4:in `foo’
from (irb):4
But I like the verbose prompt, except when I want to copy it into an email.
I’d rather keep the verbose prompt the default, and have a ‘-s’ flag (or
something, haven’t checked if ‘-s’ already exists) to give me the simple one.
Tim Bates
···
On Tue, 21 Jan 2003 11:13 am, Daniel Carrera wrote:
On Tue, Jan 21, 2003 at 09:34:00AM +0900, Gavin Sinclair wrote:
If you haven’t used irb before, get used to it! It was invoked with
–simple-prompt above (why isn’t there a short command for that?).
Maybe --simple-prompt should be the default and have a --verbose-prompt
for those who want it.