Created
August 14, 2009 17:09
-
-
Save hal0thane/167963 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
## RUBY TRICKS TO REMEMBER | |
# Parallel assignment | |
x, y = 1, 2 # Parallel assignment: x = 1; y = 2 | |
a, b = b, a # Swap the values of a & b -- no throwaway var needed! | |
# Using methods to start a code block: | |
File.open("data.txt") do |f| # Open the file 'data.txt' | |
line = f.readline # Read each line of it, in a loop | |
end # Automatically close it at the end | |
# Another example of that: | |
t = thread.new do | |
File.read("data.txt") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment