Skip to content

Instantly share code, notes, and snippets.

@jdoig
Created October 28, 2011 16:56
Show Gist options
  • Save jdoig/1322762 to your computer and use it in GitHub Desktop.
Save jdoig/1322762 to your computer and use it in GitHub Desktop.
7 Languages in 7 Weeks: Day 1
puts 'Hello, World'
puts 'Hello, Ruby'
.gsub(' ','')
.split(',')
.index('Ruby')
10.times{puts 'Big Poppa Smurf'}
(1..10).each{|i| puts "this is sentence #{i}" }

The code bellow is horrible, I was experimenting with Ruby; seeing how much I could get done with one line functions, how much I could get done without global state and side effect... I broke before ruby did, but here's hoping I find a way to corrupt it in the following 2 days of study :)

@secret = rand(10) + 1
@results = ['Too low','Congratulations you guessed it!','Too high']
def take_a_guess(guess, secret)
puts @results[(guess <=> secret) + 1]
guess == secret
end
# Game loop
print 'Can you guess the number I am thinking of? '
correct = take_a_guess(gets.to_i,@secret) while not correct
@macosgrove
Copy link

Thanks for sharing your code James. It made it clear to me that I'm still stuck in a Java mind-set!
I like your @results array and use of the spaceship operator.
You need to add 1 to @secret to get a range of 1..10 though.

@philosodad
Copy link

I like the results array and the use of guess == secret.

@jdoig
Copy link
Author

jdoig commented Oct 29, 2011

Thanks guys and good catch Mary-Anne :¬) [I've edited the code now, cheers]

@macosgrove
Copy link

macosgrove commented Oct 29, 2011 via email

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