-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.rb
62 lines (53 loc) · 1.4 KB
/
test.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
def print_show_stuff(x, &block)
puts "OK: called as bar(#{x.inspect})"
block.call("A gift from bar!") if block #if block in case no block was given.
end
def alternative(x, &block)
puts "OK: called as bar(#{x.inspect})"
block.call("A gift from bar!") if block #if block in case no block was given.
end
#alternative("without_block")
#alternative(123) {|y| puts "BLOCK: #{y} How nice =)"}
# def alternative(x, yeild)
# > puts "OK: called as bar(#{x.inspect})"
# end
#
# alternative("without_block")
# alternative(123) {|y| puts "BLOCK: #{y} How nice =)"}
#
# alternative(1234) {puts "BLOCK: How nice =)"}
# end
# class Ape
#
# # Monkey.tell_ape { "ook!" }
# # ape: ook!
# # => nil
# def self.tell_ape(&block)
# tell("ape", &block)
# end
#
# def self.tell(name, &block)
# puts "#{name}: #{block.call}"
# end
#
# self.tell_ape(){puts "BLOCK:"}
# self.tell_ape(){"BLOCK:"}
#
# end
class Monkey
def self.tell(name)
puts "#{name}: #{yield}"
end
def self.beat_around_the_bush()
return yield
end
def self.tell_ape(object)
puts object[:hello]
end
def self.tell_ape_all(object)
puts object
end
# self.tell_ape(tell("ape"){"BLOCK:"})
self.tell_ape(beat_around_the_bush(){object={test: "hi", hello: "rwaarrr im a value "} }) {puts}
self.tell_ape_all(beat_around_the_bush(){object={test: "hi", hello: "rwaarrr im a value "} }) {puts}
end