DEV Community

n350071πŸ‡―πŸ‡΅
n350071πŸ‡―πŸ‡΅

Posted on

Ruby array multiple assignment

Assignment to variables

a, b = [:hello, :world]
puts a #=> :hello
puts b #=> :world
Enter fullscreen mode Exit fullscreen mode

Assignment as arguments ( 2 Ways )

def show_two_arguments(a,b:)
  puts a
  puts b
end

show_two_arguments(:hello, b: :world)
#=> :hello
#=> :world

show_two_arguments(*[:hello, b: :world])
#=> :hello
#=> :world
Enter fullscreen mode Exit fullscreen mode

πŸ”— Parent Note

Top comments (0)