All values for b
below let me call a method with the *args
syntax.
def some_method(a)
puts a
end
b = 1
some_method(*b) # => 1
b = false
some_method(*b) # => false
b = "whatever"
some_method(*b) # => "whatever"
With nil
, I expected to get nil
, not argument error:
b = nil
some_method(*b) # => ArgumentError: wrong number of arguments (0 for 1)
What is happening here?
b = *nil; method(b)
which works fine. – Pasquinademethod
. it does spooky things to mypry
(starts printing:inspect
). I'm assuming you wouldn't do it normally but I thought it was interesting so I thought I'd mention it, I'd be interested if someone could tell me what is causing that. – Pasquinademethod(*b)
. And yes, the name "method" for a method is not good. Was just an example here. – Mansuetudeb= *b
as this will coercenil
into[]
and will leave arrays the same. – Pasquinadeb= *b; some_method(*b)
? That could work. – Mansuetudenil
) but it is at least a solution. :) – Pasquinadeb = [] if b == nil
would be more clear and better actually, but yeah. What is going on with nil? – MansuetudeObject#method
so calling your own methodmethod
won't work out so well. – Hanks:inspect
every time a string is printed. – Pasquinade