-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy path004.rb
84 lines (66 loc) · 1.64 KB
/
004.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
=begin
Desafio 004
Problema: Faça um programa que leia algo pelo teclado e mostre na tela
seu tipo primitivo e todas as informações possíveis sobre ela.
Resolução do problema:
=end
class String
def is_alnum?()
!!match(/^[[:alnum:]]+$/)
end
def is_alpha?()
!!match(/^[[:alpha:]]$/)
end
def is_letter?()
!!match?(/[[:alpha:]]/)
end
def is_space?()
!!match?(/[[:space:]]/)
end
def is_lower?()
!!match?(/[[:lower:]]/)
end
def is_upper?()
!!match?(/[[:upper:]]/)
end
def is_capitalized?()
chars.first == chars.first.upcase
end
def is_printable?()
!!match?(/\p{Print}/)
end
def is_digit?()
!!match?(/\p{Digit}/)
end
def is_decimal?()
!!match?(/\p{Nd}/)
end
def is_num?()
!!match?(/\p{N}/)
end
end
def is_indentifier?(s)
words = ['BEGIN', 'END','begin','alias', 'and','break','case', 'class',
'def','module','next','nil','not','or','redo','rescue','retry','return',
'elsif','end','false','ensure','for','if','true','undef','unless','do',
'else','super','then','until','when','while','defined?','self']
words.each do |i|
if i == s
return true
end
end
return false
end
print('Digite algo: ')
s = gets.chomp
puts"O tipo primitivo desse valor é: #{s.class}"
puts"É um número? #{s.is_num?}"
puts"É um valor alfanumérico? #{s.is_alnum?}"
puts"É texto? #{s.is_alpha?}"
puts"É um digito? #{s.is_digit?}"
puts"É um identificador? #{is_indentifier?(s)}"
puts"Está em letra minúscula? #{s.is_lower?}"
puts"Está em letra maiúscula? #{s.is_upper?}"
puts"É uma tabela de impressão? #{s.is_printable?}"
puts"É um espaço? #{s.is_space?}"
puts"Está capitalizada? #{s.is_capitalized?}"