I'm learning about the use of symbols in Ruby and have realized they act largely as references to variables, keys in hash tables, and even as a way of sending blocks in methods.
My questions is, what exactly are symbols, such as :+
:-
:*
, referencing when I use them in a method?
e.g. using :+
to sum all the values in an array:
puts [1,2,3].reduce(:+)
=> 6
gives the same result as:
puts [1,2,3].reduce {|sum, i| sum += i}
=> 6
and if I create my own version of :+
a = lambda {|sum,i| sum += i}
puts [1,2,3].reduce(&a)
=> 6
My first thought is therefore that :+
references {|sum, i| sum += i}
as an explicit block but I've had trouble finding information to confirm that.