-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobj_24.rb
More file actions
executable file
·53 lines (44 loc) · 931 Bytes
/
robj_24.rb
File metadata and controls
executable file
·53 lines (44 loc) · 931 Bytes
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
#!/usr/bin/env ruby
require "./ruler"
#-----------------------------------------------------------------------------
R("Show how one can use missing_method to do additional stuff")
class Obj
attr_accessor :obj_name
def initialize(name)
@obj_name = name
end
def dupa
puts "> DUPA from Obj class"
end
def chuj
puts "> CHUJ from Obj class"
end
def missing_method(m_name)
puts "Obj #{m_name} undefined"
end
def to_s; @obj_name; end
end
class Thing
attr_accessor :user
def initialize(user)
@user = user
end
# -------------------------------------------------------------------
def to_s
"to_s_Thing_" + @user.to_s
end
# def to_a
# [ @user ]
# end
# alias_method :to_ary, :to_a
def method_missing(method_name, *args)
puts "--- before sending #{method_name}---"
@user.send(method_name, *args)
puts "--- after sending ---"
end
end
o = Obj.new("my_object")
t = Thing.new(o)
puts t
t.dupa
t.chuj