Names starting with ":"

Please support our Ruby advertiser: SELL YOUR PRODUCT TODAY !
Reply

Join Date: Nov 2008
Posts: 75
Reputation: drjay1627 is an unknown quantity at this point 
Solved Threads: 1
drjay1627 drjay1627 is offline Offline
Junior Poster in Training

Names starting with ":"

 
0
  #1
Jun 4th, 2009
What are names starting with the ":", are they variables, constants or something else?

drjay
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 521
Reputation: pty is on a distinguished road 
Solved Threads: 37
pty's Avatar
pty pty is offline Offline
Posting Pro

Re: Names starting with ":"

 
0
  #2
Jun 5th, 2009
Originally Posted by drjay1627 View Post
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.

  1. % irb --simple-prompt
  2. >> a = :something
  3. => :something
  4. >> a.class
  5. => Symbol

Then look it up in the docs: http://www.ruby-doc.org/core/classes/Symbol.html
Last edited by pty; Jun 5th, 2009 at 4:00 pm.
Note to self... pocket cup
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,581
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 461
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: Names starting with ":"

 
0
  #3
Jun 12th, 2009
They are called 'symbols' in Ruby.
I don't accept change; I don't deserve to live.
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 1
Reputation: Kevin_poison is an unknown quantity at this point 
Solved Threads: 0
Kevin_poison Kevin_poison is offline Offline
Newbie Poster

Re: Names starting with ":"

 
0
  #4
Jul 23rd, 2009
names starting with ":" are expressions that return a symbol object e.g.
  1. Class Person
  2. attr_reader :name, :age, :sex
  3. end
  4.  
  5. me = Person.new("poison", "24", "male")

The construct :name is an expression that returns a symbol corresponding to name.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC