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 :)
Created
October 28, 2011 16:56
-
-
Save jdoig/1322762 to your computer and use it in GitHub Desktop.
7 Languages in 7 Weeks: Day 1
This file contains 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
puts 'Hello, World' |
This file contains 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
puts 'Hello, Ruby' | |
.gsub(' ','') | |
.split(',') | |
.index('Ruby') |
This file contains 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
10.times{puts 'Big Poppa Smurf'} |
This file contains 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
(1..10).each{|i| puts "this is sentence #{i}" } |
This file contains 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
@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 |
I like the results array and the use of guess == secret.
Thanks guys and good catch Mary-Anne :¬) [I've edited the code now, cheers]
:-)
…On Sat, Oct 29, 2011 at 12:06 PM, jdoig < ***@***.***>wrote:
Thanks guys and good catch Mary-Anne :) [I've edited the code now, cheers]
##
Reply to this email directly or view it on GitHub:
https://gist.github.com/1322762
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.