J
JZ
I'm trying to understand how to call methods in Ruby. Is it possible to
call parameters in different order? E.g. in Python it is very clear and
simple to use:
def fun(a=1,b=2):
return 'a:%s, b:%s' % (a,b)
print fun(b=10, a=20) # a:20, b:10
print fun(b=111) # a:1, b:111
But in similiar Ruby function I get weird results
def fun(a=1,b=2)
"a:#{a}, b:#{b}"
end
p funb=>10, :a=>20) # "a:a20b10, b:2"
p funb=>111) # "a:b111, b:2"
p fun(b=111) # "a:111, b:2"
Is it possible that such basic and usefull feature is not implemented in
Ruby??
call parameters in different order? E.g. in Python it is very clear and
simple to use:
def fun(a=1,b=2):
return 'a:%s, b:%s' % (a,b)
print fun(b=10, a=20) # a:20, b:10
print fun(b=111) # a:1, b:111
But in similiar Ruby function I get weird results
def fun(a=1,b=2)
"a:#{a}, b:#{b}"
end
p funb=>10, :a=>20) # "a:a20b10, b:2"
p funb=>111) # "a:b111, b:2"
p fun(b=111) # "a:111, b:2"
Is it possible that such basic and usefull feature is not implemented in
Ruby??