Created
December 11, 2010 17:47
-
-
Save doolin/737497 to your computer and use it in GitHub Desktop.
Simple 2D Array Behavior in 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
#!/usr/bin/env ruby | |
#Scientific programming deals with arrays of numbers. | |
#Here's a quick snippet showing how Ruby behaves with arrays. | |
strike_dip = [ [ 12.0, 30.0 ], | |
[ 43.0, 12.0 ]] | |
puts "Whole array" | |
puts strike_dip | |
puts "First pair" | |
puts strike_dip[0] | |
puts "Second pair" | |
puts strike_dip[1] | |
strike_dip.each do | sd| | |
print "Strike/dip: ", sd | |
puts | |
end | |
=begin | |
This script outputs: | |
Whole array | |
12.0 | |
30.0 | |
43.0 | |
12.0 | |
First pair | |
12.0 | |
30.0 | |
Second pair | |
43.0 | |
12.0 | |
Strike/dip: [12.0, 30.0] | |
Strike/dip: [43.0, 12.0] | |
Easy peasy. | |
=end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment