Three things I didn't know Ruby does
Contents
Edit: I was misled!
Illustrated here. Hints below.
>> def inspect_x_and_y(x,y); puts "x: %p, y: %p" % [x, y]; end
=> nil
>> inspect_x_and_y(y={"hello" => "world"},x=[1,2,3])
x: {"hello"=>"world"}, y: [1, 2, 3]
The bits I didn’t know about:
"Format strings using a %% sign, %s, %s!" % [ "just like in python", "but with arrays" ]
- The
%p
formatting character is the same asinspect
. - You can call methods with
method_name(param2=val2, param1=val1)
, also like in python. No you can’t! This code sets external variables called y and x.
How embarassing… :(