File: array_member.rb

package info (click to toggle)
ruby-cstruct 1.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 420 kB
  • ctags: 137
  • sloc: ruby: 1,008; makefile: 7
file content (29 lines) | stat: -rw-r--r-- 501 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# CStruct Examples
require 'cstruct'

# example:
# struct T in C\C++ (32-bit platform): 
# 
# struct T
# {
#    int element[8];
# }; 

# struct T in Ruby: 
class T < CStruct
  int32:elements,[8]
end

# create a T's instance
t_array = T.new

(0..7).each do |i|
  t_array.elements[i] = i  # assign like as C language
end

# output
(0..7).each {|i| puts "t_array.elements[#{i}] = #{t_array.elements[i]}" }


# Actually,t_array.elements.class is Array. So..
t_array.elements.each {|element| puts element }