-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex08_1.rb
executable file
·37 lines (25 loc) · 1022 Bytes
/
ex08_1.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
#!/usr/bin/env ruby
# This one's interesting
# Each puts statement format string [ ] requires 4 arguments or it won't work, you'll get a "too few arguments error"
#
formatter = "%s %s %s %s"
puts formatter % [1, 2, 3, 4]
# puts formatter % [1, 2, 3]
# ./ex08_1.rb:6:in `%': too few arguments (ArgumentError)
puts formatter % ["one", "two", "three", "four"]
# puts formatter % ["one", "two", "three"]
# ./ex08_1.rb:10:in `%': too few arguments (ArgumentError)
puts formatter % [true, false, false, true]
# puts formatter % [true, false, false]
# ./ex08_1.rb:14:in `%': too few arguments (ArgumentError)
puts formatter % [formatter, formatter, formatter, formatter]
# puts formatter % [formatter, formatter, formatter]
# ./ex08_1.rb:19:in `%': too few arguments (ArgumentError)
puts formatter % [
"I had this thing.",
"That you coudl type up right.",
"But it didn't sing.",
"So I said goodnight."
]
# So really all of these puts statements above are doing this:
puts "%s %s %s %s" % [1, 2, 3, 4]