Skip to content

Instantly share code, notes, and snippets.

@hal0thane
Created August 14, 2009 17:09
Show Gist options
  • Save hal0thane/167963 to your computer and use it in GitHub Desktop.
Save hal0thane/167963 to your computer and use it in GitHub Desktop.
## 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