Symbols confuson

in this,

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]

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)

Why is a symbol sometimes have a : before or after the name?

A symbol always has a : in front of its name, usually followed by a non-quoted string, e.g. :pullo
They are also immutable. Their value remains constant during the entirety of the program and they never appear on the left side of an assignment.

In the above example, I think you’re probably getting confused with the arguments you are passing to the add method.

As of Ruby 1.9 hashes can be declared using a new syntax.

Ruby 1.8 syntax:

{:key1 => "value1", :key2 => "value2"}

Ruby 1.9 syntax:

{key1: "value1", key2: "value2"}

So this:

puts add(1.0134, -5.568, absolute: true)

Could also be written like this:

puts add(1.0134, -5.568, :absolute => true)

and this:

puts add(1.0134, -5.568, absolute: true, round: true, precision: 2)

could also be written like:

puts add(1.0134, -5.568, :absolute => true, :round => true, :precision => 2)

In short: symbols always have a : in front of them. You are getting confused with the new Hash syntax introduced in Ruby 1.9

Further reading: