s.split('').?.? Ruby syntax

Go To StackoverFlow.com


I am new to ruby on rails and started a tutorial and found out the following function

 def string_shuffle(s)
>>   s.split('').?.?
>> end
=> nil
>> string_shuffle("foobar")

What does s.split('').?.? do? I know the split method but i have no idea what the two question marks are for. I saw "? used in boolean methods, but i couldnt understand how this one works. I tried to google it but, I couldnt find it at all.

2012-04-04 17:40
by WowBow


To quote the tutorial in question:

By replacing the question marks in Listing 4.10 with the appropriate methods, combine split, shuffle, and join to write a function that shuffles the letters in a given string.

Listing 4.10 is an exercise where the two question marks are meant to be replaced with actual method calls.

2012-04-04 17:50
by Charles Caldwell
Ohhh. Shame on me. Any ways, thank you - WowBow 2012-04-04 18:43


This code is not valid

You can see split returns an array : http://www.ruby-doc.org/core-1.9.3/String.html#method-i-split

And there is no method called ? in Array : http://www.ruby-doc.org/core-1.9.3/Array.html

2012-04-04 17:45
by Vallières
Reference: You can find it here http://ruby.railstutorial.org/chapters/rails-flavored-ruby?version=3.2#sec:exercise - WowBow 2012-04-04 17:46
It is on Listing 4.10. It is ruby rails version 3 i think - WowBow 2012-04-04 17:47
Those are exercises, you need to fill the blanks, you need to replace the ? with actual functions - Vallières 2012-04-04 17:51