Ruby - Methods - Variable Arguments

Sort by

recency

|

52 Discussions

|

  • + 0 comments

    I way overthought this problem, but the problems are often written poorly and this one definitely was. Don't overthink this and you will find the solution quite easily.

    def full_name(first, *mid, last)
    [first, *mid, last].join(' ')
    end
    
  • + 0 comments
    def full_name(first, *rest)
        rest.reduce(first) { |o, x| o + ' ' + x}
    end
    
  • + 0 comments
    # Your code here
    def full_name(first_name, *middle_and_last_names)
      ([first_name] + middle_and_last_names).join(" ")
    end
    
  • + 0 comments

    Ruby Compiled solutions https://github.com/LinaOrmos/Ruby/tree/main

  • + 0 comments

    def full_name(first, *rest) first + " " + rest.join(" ") end