-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobj_09.rb
executable file
·62 lines (52 loc) · 1.04 KB
/
robj_09.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
#!/usr/bin/env ruby
require './ruler'
STDOUT.sync = true
STDERR.sync = true
#-----------------------------------------------------------------------------
R("just check what :<something> does");
def ex_class()
colors = [ :red, :green, :blue, :yellow ]
colors.each do |c|
puts "> #{c}"
end
end
ex_class()
#-----------------------------------------------------------------------------
R("Just check what talk() does");
class Thing
def talk
puts "-- This is original talk() --"
end
end
t0 = Thing.new
t0.talk
class Thing
alias :oldtalk :talk
def talk
puts "-- Thing->talk --"
oldtalk
end
end
t1 = Thing.new
t1.talk
#-----------------------------------------------------------------------------
R("Just check what &does");
class Array
alias :oldsort :sort
def sort(&block)
puts "Size: #{size}"
if size > 10000
$stderr.puts "###### Warn: size > 10000!"
end
oldsort(&block)
end
end
(0...15000).to_a.sort
#---------------------------
R("understanding *args")
def method(*args)
args.each do |a|
puts "Arg: #{a}"
end
end
method(1)