Ruby - chaining methods and returning array -


I have some methods for a class that has ["1", "3", "2" , "6", "2"] . It's fine that these string arrays are not numerical, I have another way that takes an array, and it has a = 1 @ dice = [] end df roll @roll = [] x = 5 - @ Dice.length x.times do | I | @ Roll [i] = RAND (6) + 1 end # roll # ["1", "3", "2", "6", "2"] End DEF show @ hate # ["1", "3 "," 6 "] end def line (some) temp =" something " Do it X | Temporary & lt; & Lt; X + "Finally # 39" or "1 3 2 6 2" End End

Then I want to be able to chain series together so that I can do it

  first = turn on.New ago.roll.line first.show.line  

However, I do not know how to do it, and I have not been able to find heaven online, I have returned myself , but I can not really understand what it does. Line Pad If I take it to any other method, then the problem is actually only dealing with Chenning and return.

If someone can not help with code only

Thank you!

Since your #roll and #show Methods come back an array, you should actually be able to first.roll.line a method array # line .

BTW, already has the Array # join which is the array Won also included with a string, like your # line method, so you can use first.roll.join ( '') and get rid of the # line method.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -