DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Ruby (http://www.daniweb.com/forums/forum73.html)
-   -   Names starting with ":" (http://www.daniweb.com/forums/thread195842.html)

drjay1627 Jun 4th, 2009 4:13 pm
Names starting with ":"
 
What are names starting with the ":", are they variables, constants or something else?

drjay

pty Jun 5th, 2009 4:00 pm
Re: Names starting with ":"
 
Quote:

Originally Posted by drjay1627 (Post 883731)
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

~s.o.s~ Jun 12th, 2009 2:53 pm
Re: Names starting with ":"
 
They are called 'symbols' in Ruby.

Kevin_poison Jul 23rd, 2009 3:15 am
Re: Names starting with ":"
 
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.


All times are GMT -4. The time now is 2:34 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC