Created
February 17, 2014 12:17
-
-
Save Rosa-Fox/9049568 to your computer and use it in GitHub Desktop.
Splitting string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Tweet | |
def tweets(string) | |
@tweet = string | |
end | |
def tweetsplit | |
@tweet.split('/w') | |
end | |
tweet1 = Tweet.new | |
tweet1.tweets("I'm not a big fan of roast dinners, you know?") | |
puts tweet1.tweetsplit | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
BTW, good call on creating your own Tweet class. I know this isn't part of the exercise but I thought I'd put some feedback down anyway if you're curious. Ignore if you're busy!
I would probably have accepted the tweet string in the initialiser and set it there like this:
That way you can create a new tweet like this:
Also, I would have called
tweetsplit
,words
instead though as I think it's a bit more indicative of what you're getting out of the method (we already know it's a tweet and the fact that you'resplitting
it is unnecessary detail for whoever's using the object). Calling it would then read like this:You could of course then do line 13 all in one hit with:
Also, indentation 😄