Compound data type: Difference between revisions
Content added Content deleted
Line 1,245: | Line 1,245: | ||
=={{header|Ruby}}== |
=={{header|Ruby}}== |
||
<lang ruby>Point = Struct.new(:x,:y) |
<lang ruby>Point = Struct.new(:x,:y) |
||
pt = Point.new(6,7) |
|||
puts pt.x #=> 6 |
|||
pt.y = 3 |
|||
puts p |
|||
=> #<struct Point x=6, 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</lang> |
|||
=={{header|Scala}}== |
=={{header|Scala}}== |