2. Sending long Tweets
“Can we just send a really long tweet into
multiple tweets?” –me
“Like texting? I think that would require
recursion.” –David
Whoa?! Recursion is actually useful in the real
world?
3. Recursion Explained
“Really long Tweet”
Tweet Method Characters after 140
1st
140
Charc
-ters
Get Tweeted
4. My code
require 'jumpstart_auth'
class JSTwitter
attr_reader :client
def initialize
puts "Initializing"
@client = JumpstartAuth.twitter
end
def run
puts "I totally just figured out a way to make my twitter program use recursion and
tweet my messages in blocks of 140 characters at a time, not matter how long they are.
For all of my friends reading this who are not computer programmers, I'm sorry that
makes no since to you, but I'm super excited about it! If you are a very experienced
computer programmer, you also may be confused, if you do not remember what it was like
to be a beginner, and get excited about doing very simple things."
end
def tweet(message)
if message.length> 140
message[0..139] = message
@client.update(message)
message[140..-1].tweet
else
@client.update(message)
end
end
end
jst = JSTwitter.new
jst.run
5. Code Update
• require 'jumpstart_auth'
• class JSTwitter
• attr_reader :client
• def initialize
• puts "Initializing"
• @client = JumpstartAuth.twitter
• end
• def run
• tweet "Look at my really, really, really, really, really,
• really, really, really, really, really, really, really,
• really, really, really, really, really, really, really,
• really, really, really, really, really, really, really,
• really, really, really, really, really, really, really,
• really, really, really, really, really, really, really,
• really, really, really, really, really, really, really,
• really, really, really, really, really, really, really,
• long tweet. I am the greatest programmer in the universe!"
• end
• def tweet(message)
• if message.length> 140
• message[0..139] = message
• @client.update(message)
• message[140..-1].tweet
• else
• @client.update(message)
• end
• end
• end
• jst = JSTwitter.new
• jst.run