puts"Let's practice everything."puts"You\'d need to know \'bout escapes with \\ that do \n newlines and \t tabs."poem=<<MULTI_LINE_STRING\tThe lovely worldwith logic so firmly plantedcannot discern \n the needs of lovenor comprehend passion from intuitionand requires an explanation\n\t\twhere there is none.MULTI_LINE_STRINGputs"--------------"putspoemputs"--------------"five=10-2+3-6puts"This should be five: #{five}"defsecret_formula(started)jelly_beans=started*500jars=jelly_beans/1000crates=jars/100returnjelly_beans,jars,cratesendstart_point=10000beans,jars,crates=secret_formula(start_point)puts"With a starting point of: #{start_point}"puts"We'd have #{beans} beans, #{jars} jars, and #{crates} crates."start_point=start_point/10puts"We can also do that this way:"puts"We'd have %s beans, %s jars, and %s crates."%secret_formula(start_point)
你應該看到的結果
$ ruby ex24.rb
Let's practice everything.
You'd need to know 'bout escapes with \ that do
newlines and tabs.
--------------
The lovely world
with logic so firmly planted
cannot discern
the needs of love
nor comprehend passion from intuition
and requires an explanation
where there is none.
--------------
This should be five: 5
With a starting point of: 10000
We'd have 5000000 beans, 5000 jars, and 50 crates.
We can also do that this way:
We'd have 500000 beans, 500 jars, and 5 crates.
$