Ruby - Stack Pop Operation


Ruby - Stack Pop Operation

Sample ruby code for stack pop operation :

wikiTechy_array = ["a","b","c","d","e","f"]
puts "pop="+ wikiTechy_array.pop		
wikiTechy_array.inspect 

Code Explanation :

    Stack array declared as wikiTechy_array = ["a", "b", "c", "d", "e", "f"].

    puts "pop="+ wikiTechy_array.pop takes out the last added value, that is f is out of array and prints pop=f.

    So the code wikiTechy_array.inspect prints the array values as ["a", "b", "c", "d", "e", "f"]

  • puts is not used before the code wikiTechy_array.inspect. Hence the character “”, appears before each quotation marks(“) as shown above.


Workshop

IOT Hackathon
Webinar

Join our Community

Advertise