Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Print the string "Hello, world."
- puts "Hello, world."
- # For the string "Hello, Ruby." find the index of the word "Ruby."
- puts "Hello, Ruby.".index("Ruby.")
- # Print your name ten times.
- 10.times { puts "your name" }
- # Print the string "This is sentence number 1," where the number 1 changes from 1 to 10.
- (1..10).each { |t| puts "This is sentence number #{t}" }
- # Run a Ruby program from a file
- # This is no exercise, but here is a cool tip: use Aptana Studio and you can easily run any Ruby file. Even more, it's quite a cool IDE, far away from JDT in Eclipse, but still:
- http://aptana.com/products/studio3/download
- # Program that picks a random number and let the player guess it
- number = rand(10)
- guess = 11
- while (number != guess)
- puts "guess >"
- guess = gets.chomp.to_i
- puts "#{(guess < number) ? "too low" : (guess > number) ? "too high" : "yey! you got it."}"
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement