Skip to content

Instantly share code, notes, and snippets.

@Rosa-Fox
Created February 17, 2014 12:17
Show Gist options
  • Save Rosa-Fox/9049568 to your computer and use it in GitHub Desktop.
Save Rosa-Fox/9049568 to your computer and use it in GitHub Desktop.
Splitting string
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
@Najaf
Copy link

Najaf commented Feb 17, 2014

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:

class Tweet
  def initialize(tweet)
    @tweet = tweet
  end
end

That way you can create a new tweet like this:

tweet = Tweet.new("I'm not a big fan of roast dinners, you know?")

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're splitting it is unnecessary detail for whoever's using the object). Calling it would then read like this:

tweet.words # => returns an array of words in the tweet.

You could of course then do line 13 all in one hit with:

puts Tweet.new("I'm not a big fan of roast dinners, you know?").words

Also, indentation 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment