P
paul
Hi all,
Probably I'm trying something impossible, but when giving default
values for arguments to a method call, do I have to give default-values
for *all* arguments?
irb(main):001:0> class A
irb(main):002:1> def a(b = 0, c, d = '', e)
irb(main):003:2> puts b, c, d, e
irb(main):004:2> end
irb(main):005:1> end
SyntaxError: compile error
(irb):2: syntax error
def a(b = 0, c, d = '', e)
^
(irb):2: syntax error
(irb):5: syntax error
from (irb):5
And also when giving default-values to all arguments, omitting
arguments when calling the method doesn't seem to be a succes:
irb(main):001:0> class B
irb(main):002:1> def b(c = 0, d = 1, e = 2)
irb(main):003:2> puts c, d, e
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> B.new.b(1,2,3)
1
2
3
=> nil
irb(main):007:0> B.new.b(1,,3)
SyntaxError: compile error
(irb):7: syntax error
B.new.b(1,,3)
^
from (irb):7
Is it impossible or I'm I just coding it wrong?
Cheers,
Paul
Probably I'm trying something impossible, but when giving default
values for arguments to a method call, do I have to give default-values
for *all* arguments?
irb(main):001:0> class A
irb(main):002:1> def a(b = 0, c, d = '', e)
irb(main):003:2> puts b, c, d, e
irb(main):004:2> end
irb(main):005:1> end
SyntaxError: compile error
(irb):2: syntax error
def a(b = 0, c, d = '', e)
^
(irb):2: syntax error
(irb):5: syntax error
from (irb):5
And also when giving default-values to all arguments, omitting
arguments when calling the method doesn't seem to be a succes:
irb(main):001:0> class B
irb(main):002:1> def b(c = 0, d = 1, e = 2)
irb(main):003:2> puts c, d, e
irb(main):004:2> end
irb(main):005:1> end
=> nil
irb(main):006:0> B.new.b(1,2,3)
1
2
3
=> nil
irb(main):007:0> B.new.b(1,,3)
SyntaxError: compile error
(irb):7: syntax error
B.new.b(1,,3)
^
from (irb):7
Is it impossible or I'm I just coding it wrong?
Cheers,
Paul