Advertisement
ice09

7l7w ruby day1

Nov 2nd, 2011
411
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.88 KB | None | 0 0
  1. # Print the string "Hello, world."
  2. puts "Hello, world."
  3.  
  4. # For the string "Hello, Ruby." find the index of the word "Ruby."
  5. puts "Hello, Ruby.".index("Ruby.")
  6.  
  7. # Print your name ten times.
  8. 10.times { puts "your name" }
  9.  
  10. # Print the string "This is sentence number 1," where the number 1 changes from 1 to 10.
  11. (1..10).each { |t| puts "This is sentence number #{t}" }
  12.  
  13. # Run a Ruby program from a file
  14. # 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:
  15.  
  16. http://aptana.com/products/studio3/download
  17.  
  18. # Program that picks a random number and let the player guess it
  19. number = rand(10)
  20. guess = 11
  21. while (number != guess)
  22.   puts "guess >"
  23.   guess = gets.chomp.to_i
  24.   puts "#{(guess < number) ? "too low" : (guess > number) ? "too high" : "yey! you got it."}"
  25. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement