These are chat archives for jhliberty/jhliberty

25th
Jan 2015
sharpattack
@sharpattack
Jan 25 2015 00:00
hey henry(or anyone who wants to try) i have a ruby question for you
John-Henry Liberty
@jhliberty
Jan 25 2015 00:00
Fire away
sharpattack
@sharpattack
Jan 25 2015 00:01
how would you create a method that's take in a string of words, and return a new string, with the first character moved to the end of the word, while also retaining the capitalization and punctuation?
i.e. "My name is Austin, and I love coding in Ruby!" => "Ym amen si Ustina, nda i ovel odingc ni Ubyr!"
that lone "I" should remain capitalized, "nda I ovel"
John-Henry Liberty
@jhliberty
Jan 25 2015 00:10
that’s an interesting one
sounds like a code kata =p
sharpattack
@sharpattack
Jan 25 2015 00:11
lol yea it pretty much is an exercise
i'll figure it out eventually,
John-Henry Liberty
@jhliberty
Jan 25 2015 00:12
in psuedo code i would probably take the sentence, split it on space, check if the first letter was capitalized, shift the first character to the back of the array, if the first letter had been capitalized, change the new first character to a capital, then rejoin all the pieces
I would remain capital within on those constraints as well
sharpattack
@sharpattack
Jan 25 2015 00:13
how would you check if a character is capitalized?
i know #capitalize? or #upcase? are not methods
John-Henry Liberty
@jhliberty
Jan 25 2015 00:14
couple ways, you could use regex or a method that runs upcase on the character and checks for equivilence
sharpattack
@sharpattack
Jan 25 2015 00:14
ahh ok
John-Henry Liberty
@jhliberty
Jan 25 2015 00:14
x == x.upcase
sharpattack
@sharpattack
Jan 25 2015 00:14
i see
i'll play around with a couple, and let you know what i ended up with
John-Henry Liberty
@jhliberty
Jan 25 2015 00:16
def is_capitalized? c
  c == c.upcase
end
nice - code highlighting in this chat
handy
John-Henry Liberty
@jhliberty
Jan 25 2015 00:40
here’s a crude example
s.split(" ").map do |x|
  caps = x[0] == x[0].upcase
  x.insert(-1, x[0])
  x[1] = x[1].upcase if caps
  puts x[1..-1]
end
sharpattack
@sharpattack
Jan 25 2015 03:22
what's happening at x.insert(-1, x[0])?
you also forgot to downcase the original upcase, so i'm guessing x[0] = x[0].downcase if caps goes in there somehwere?
John-Henry Liberty
@jhliberty
Jan 25 2015 03:23
inserting the x[0] char as the last psoition
x.insert(-1, x[0].downcase)
Chirag Gupta
@ChicagoGupta
Jan 25 2015 18:54
where's the retweet button on this thing!!
John-Henry Liberty
@jhliberty
Jan 25 2015 18:57
lol
xuan is here
wha wha
Xuan Yue
@midnightnova23
Jan 25 2015 18:57
Ello
Chirag Gupta
@ChicagoGupta
Jan 25 2015 18:58
orly
John-Henry Liberty
@jhliberty
Jan 25 2015 21:03
yarly