J
Jarmo Pertman
Hello!
I've just happened to find strange behaviour when trying to explode
parameters.
Why doesn't it work?
irb(main):007:0> lambda {|*parameters| *parameters.class}
SyntaxError: compile error
(irb):7: syntax error, unexpected '}', expecting tCOLON2 or '[' or '.'
from (irb):7
from :0
class is Array if 0 or more parameters given
irb(main):009:0> l = lambda {|*parameters| p *parameters.class}
=> #<Proc:0x04b7e510@(irb):9>
irb(main):010:0> l[]
Array
=> nil
class is Array if some parameters given
irb(main):012:0> l = lambda {|*parameters| x = *parameters; p x.class}
=> #<Proc:0x04b2c880@(irb):12>
irb(main):013:0> l[1,2]
Array
=> nil
class is NilClass instead of Array?
irb(main):014:0> l[]
NilClass
=> nil
Any ideas why class is NilClass instead of Array if *parameters is
assigned to local variable? I'd expect it to be always an Array and if
no parameters given then an empty Array.
Best Regards,
Jarmo
I've just happened to find strange behaviour when trying to explode
parameters.
Why doesn't it work?
irb(main):007:0> lambda {|*parameters| *parameters.class}
SyntaxError: compile error
(irb):7: syntax error, unexpected '}', expecting tCOLON2 or '[' or '.'
from (irb):7
from :0
class is Array if 0 or more parameters given
irb(main):009:0> l = lambda {|*parameters| p *parameters.class}
=> #<Proc:0x04b7e510@(irb):9>
irb(main):010:0> l[]
Array
=> nil
class is Array if some parameters given
irb(main):012:0> l = lambda {|*parameters| x = *parameters; p x.class}
=> #<Proc:0x04b2c880@(irb):12>
irb(main):013:0> l[1,2]
Array
=> nil
class is NilClass instead of Array?
irb(main):014:0> l[]
NilClass
=> nil
Any ideas why class is NilClass instead of Array if *parameters is
assigned to local variable? I'd expect it to be always an Array and if
no parameters given then an empty Array.
Best Regards,
Jarmo