What are names starting with the ":", are they variables, constants or something else?

drjay

What are names starting with the ":", are they variables, constants or something else?

drjay

In ruby if you don't know what class an object is you can use it's class method and the docs to find out.

% irb --simple-prompt
>> a = :something
=> :something
>> a.class
=> Symbol

Then look it up in the docs: http://www.ruby-doc.org/core/classes/Symbol.html

They are called 'symbols' in Ruby.

names starting with ":" are expressions that return a symbol object e.g.

Class Person
  attr_reader :name, :age, :sex
end

me = Person.new("poison", "24", "male")

The construct :name is an expression that returns a symbol corresponding to name.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.