Ruby - Methods - Variable Arguments

Sort by

recency

|

51 Discussions

|

  • + 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

  • + 0 comments

    Solution 1:

    def full_name(*str)
        str.inject { |a, b| a + ' ' + b }
    end
    

    Solution 2:

    def full_name(*str)
        str.join(' ')
    end