-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobj_07.rb
executable file
·54 lines (47 loc) · 903 Bytes
/
robj_07.rb
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env ruby
require "./ruler"
#-----------------------------------------------------------------------------
R("Simple puts")
f = File.open("data_robj07.txt", "w")
f.putc('c')
f.close
puts "OK" if f.closed?
#-----------------------------------------------------------------------------
R("Check ? in methods")
class Sample
def is_ok?
return 1
end
end
s = Sample.new
puts "Sample OK" if s.is_ok?
#------------------------------------------------------------------------------
R("Simple regex match")
words = %w(
wojciech
koszek
adam
taku
ssss
)
words.each do |w|
if w =~ /^w/
puts "Starts with 'w'"
end
end
#-----------------------------------------------------------------------------
R("Regex object checking");
words2 = %w(
wojciech
koszek
adam
taku
ssss
)
re_w = /^w/
words2.each do |w|
puts "Word #{w.rjust(10)}"
if re_w.match(w)
puts "...matched re_w"
end
end