Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR RUBY

rails add element to array

# Ruby code for append() method
# adding elements at the end
    
# declaring array
a = [18, 22, 33, 4, 5, 6]

b = [5, 4, 22, 1, 88, 9]
 
c = [18, 22, 33, 40, 50, 6]
   
# appending array or element at the end of the array
puts "adding elements in a : #{a.append(b)}

"
   
puts "adding elements in b : #{b.append("ratttt")}

"
   
puts "adding elements in c : #{c.append(b)}

"

#results
#adding elements in a : [18, 22, 33, 4, 5, 6, [5, 4, 22, 1, 88, 9]]
#adding elements in b : [5, 4, 22, 1, 88, 9, "ratttt"]
#adding elements in c : [18, 22, 33, 40, 50, 6, [5, 4, 22, 1, 88, 9, "ratttt"]]
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #rails #add #element #array
ADD COMMENT
Topic
Name
1+8 =