Skip to content

Instantly share code, notes, and snippets.

@doolin
Created December 11, 2010 17:47
Show Gist options
  • Save doolin/737497 to your computer and use it in GitHub Desktop.
Save doolin/737497 to your computer and use it in GitHub Desktop.
Simple 2D Array Behavior in Ruby
#!/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