def add(a_number, another_number, options = {})
sum = a_number + another_number
sum = sum.abs if options[:absolute]
sum = sum.round(options[:precision]) if options[:round]
sum
end
puts add(1.0134, -5.568)
puts add(1.0134, -5.568, absolute: true)
puts add(1.0134, -5.568, absolute: true, round: true, precision: 2)
-4.5546
4.5546
4.55
j
stuff ;)
its the assignment of the "named parameter"
in the function call
puts add(1.0134, -5.568, absolute: true)the function takes 3 parameters, the first two are in your case floats and the third one is an "object/structure/hashmap".
what is happening that every parameter after the first two will be added to the "third one". you want to easily access them ofc so you name them
like
absoluteso in your function you only have 3 params but inside of the options you can overload this is a neat syntax:absolute basically resolves the index in the container. btw that's a function in your case not a method ... functions -> no object