This commit is contained in:
Ingy döt Net 2013-10-27 22:24:23 +00:00
parent 6f050a029e
commit 776bba907c
3887 changed files with 59894 additions and 7280 deletions

View file

@ -2,3 +2,5 @@
Create a compound data type Point(x,y).
A compound data type is one that holds multiple independent values. See also [[Enumeration]].
{{Template:See also lists}}

View file

@ -0,0 +1,2 @@
point.x=3;
point.y=4;

View file

@ -0,0 +1 @@
point = [3,4];

View file

@ -1,5 +1,15 @@
Point = Struct.new(:x,:y)
p = Point.new(6,7)
p.y=3
puts p
=> #<struct Point x=6, y=3>
pt = Point.new(6,7)
puts pt.x #=> 6
pt.y = 3
puts pt #=> #<struct Point x=6, y=3>
# The other way of accessing
pt = Point[2,3]
puts pt[:x] #=> 2
pt['y'] = 5
puts pt #=> #<struct Point x=2, y=5>
pt.each_pair{|member, value| puts "#{member} : #{value}"}
#=> x : 2
#=> y : 5