-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathedutechional.rb
116 lines (92 loc) · 1.48 KB
/
edutechional.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
p name = "Den"
p address = ["Kazan", "Mira 12"]
=begin
p "What is you name?"
name = gets.chomp
if name == "Den"
p true
else
p false
end
=end
p "text".upcase
p "Text".downcase
p "text".reverse
str = " Hi world spam "
p str.gsub "spam",""
p str.strip
p str.size
p str.split.size
=begin
class Test
def self.one
p "one"
end
def two
p "two"
end
end
a = Test.new
Test.one
a.two
=end
i = 0
while i < 10
i += 1
puts "Hi Ruby"
end
arr = [12,14,34,67,89]
arr.each do |i|
p i
end
for i in 0..10
p i
end
(1..10).to_a.select {|x| x.even?}
(1..10).to_a.select do |x|
x.even?
end
arr = %w(The quick brown fox over the lazy dog)
arr.select {|x| x.length > 5}
["1","2.0","77"].map{|x| p x.to_i}
("a".."g").to_a.map{|i| p i*2}
total = 0
[12,45,23,74].each do |i|
total += i
end
p total
p [12,45,23,74].inject(&:+)
p [12,45,23,74].inject(&:*)
arr = ["one","two","true"]
p arr.join(",")
people ={den: 322, oleg: 12, climent: 94}
p people[:den]
people.delete(:oleg)
p people
people.each_key do |key|
puts key
end
=begin
class ApiConnector
attr_accessor :title, :description, :url
def test_method
puts "testing class call"
end
end
api = ApiConnector.new
p api.url = "google.com"
api.test_method
=end
arr = ["index.html", "index.rb","hi.rb"]
p arr.select{|x| x =~ /\.rb/}.map{|x| x[0..-4]}
p arr.grep(/(.*)\.rb/){$1}
class String
def censor(bad_word)
self.gsub! "#{bad_word}", "CENSORED"
end
def num_of_chars
size
end
end
p "Bad post idiot".censor("idiot")
p "Hi world".num_of_chars