14. # With a single argument (index)
"0123456789".slice(0) => 48
"0123456789"[4] => 52
"0123456789".slice(10) => nil
15. # With a single argument (index)
"0123456789".slice(0) => 48
"0123456789"[4] => 52
"0123456789".slice(10) => nil
# ?4 => 52 and 52.chr => "4"
16. # With a single argument (index)
"0123456789".slice(0) => 48
"0123456789"[4] => 52
"0123456789".slice(10) => nil
# ?4 => 52 and 52.chr => "4"
# To get a single character
"0123456789".slice(4,1) => "4"
"0123456789"[3..3] => "3"
My name... Twitter... First MOTM...
Hope to lower the bar: don’t need big topic, deep insights or vast experience...
In spirit of more beginner friendly topics... Just ONE method.
Encourage IRB-ing-along... Stop me if want to see a slide longer...
(Encourage questions and answers from audience...)
Don’t need to talk about hot deploying distributed Camping apps from a Merb app using Sinatra.
TODO: slide with can and tomato (Ginsu reference) ?
I’ll cover aspects of the slice method in the following examples.
Primary version.
Take time here... PAUSE.
Can’t have a negative length.
Beware strange behavior at the end of Strings.
10 here is a valid range, but not a valid individual index (see slide 10).
Remember to PAUSE...
NOTE: http://www.nabble.com/ruby-string-slice----w--range,-weird-end-behavior-td23455258.html
A Ruby string is not a *char[] and the index points are intersticies _between_ an array of characters, not the addresses of those characters.Half steps, fence posts... (There is an index, but no value?)
Can’t have a negative length.
Beware strange behavior at the end of Strings.
10 here is a valid range, but not a valid individual index (see slide 10).
Remember to PAUSE...
NOTE: http://www.nabble.com/ruby-string-slice----w--range,-weird-end-behavior-td23455258.html
A Ruby string is not a *char[] and the index points are intersticies _between_ an array of characters, not the addresses of those characters.Half steps, fence posts... (There is an index, but no value?)
If your length argument is longer than the string remainder, you get up to the end.
No matches result in nil results.
Remember to PAUSE...
Character codes...
See slide 7 regarding index 10 versus range 10.
Halfway. Take time...
Character codes...
See slide 7 regarding index 10 versus range 10.
Halfway. Take time...
Remember to PAUSE...
Remember to PAUSE...
Remember to PAUSE...
Remember to PAUSE...
The size of the slice and its replacement don’t have to match.
Shorter, and longer...
Remember to PAUSE...
The size of the slice and its replacement don’t have to match.
Shorter, and longer...
Remember to PAUSE...
Finally...
Try it!
Even with the “Slice Bang!”
IRB, unit test...
Answers from the audience are appreciated, as well.
Any slides people want to see again?