6. Splat 6/19


Do anyone could help me, please ? I have a big problem whith the method cubertino.
Could you explain why the parameters “what up” is always there instead of vanishing like the others. Normally, it would be consider like a friends 'parameters , wouldn’t it?

for example

def what_up(greeting, *friends)
friends.each { |friend| puts “#{greeting}, #{friend}!” }

what_up(“What up”, “Ian”, “Zoe”, “Zenas”, “Eleanor”)

To the result (the output)
“What up, Ian” instead of "What up, What up!"



Same deal here, I have a hard time telling what you mean to happen and what does happen, and it isn’t possible to run your code because the forum was allowed to reformat it, change it

Looking at the code I would expect 4 lines to print, you’ve only shown one line - so I don’t know what you see or what you expected to see

Not sure what you mean by vanishing. Your program prints text, there’s no vanishing happening in that is there?

After replacing your quotes (and indenting, though that doesn’t affect the outcome), I get:

def what_up(greeting, *friends)
  friends.each { |friend| puts "#{greeting}, #{friend}!" }

what_up("What up", "Ian", "Zoe", "Zenas", "Eleanor")

which prints:

What up, Ian!
What up, Zoe!
What up, Zenas!
What up, Eleanor!


Thank you Ionathan for your quick answer!

My problem is about the latest line. I expected to see something like

"#{greeting} ===> “what up”
"#{friends} ====> “what up” or “Ian” or "Zoe’… so parameters from the function what up()

I’m waiting for your answer soon.

See you.



Still not following.
Perhaps the confusion is about what your two parameters refer to.
There’s an easy way to find out: print them.

def what_up(greeting, *friends)
  puts "greeting: #{greeting.inspect}"
  puts "friends: #{friends.inspect}"
  friends.each { |friend| puts "#{greeting}, #{friend}!" }

what_up("What up", "Ian", "Zoe", "Zenas", "Eleanor")


Thank you for your answer, dude!

I didn’t notice the symbol *which means the function could receive one or more arguments.

It’s ok now. You’re nice.

See you.



This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.