2 Replies - 2610 Views - Last Post: 06 August 2016 - 01:30 AM Rate Topic: -----

#1 gerome0123  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 07-July 16

what is the different of @ and : in ruby

Posted 07 July 2016 - 04:45 PM

Hi i'm new in rubyonrails and i just wondering the different of the @ and : for example i had article model that compose title and description in my tutorial he use :title and :description. i dont know that is the use of that ":" and also i saw this code @article i want to know what is the use of this "@"
Is This A Good Question/Topic? 0
  • +

Replies To: what is the different of @ and : in ruby

#2 xclite  Icon User is offline

  • I wrote you an code
  • member icon


Reputation: 1237
  • View blog
  • Posts: 4,028
  • Joined: 12-May 09

Re: what is the different of @ and : in ruby

Posted 07 July 2016 - 06:26 PM

Ok. Something like :hello is called a "symbol" in Ruby. I mentally think of these like enums in Java - essentially they're a useful named constant that I can pass around and refer to.

See this link for more information: http://programmers.s...-symbol-in-ruby

Something named @variable_name is an instance variable within a class. @@variable_name means the variable is a class (in some languages, this is similar to a "static") variable. variable_name is a local variable.
Was This Post Helpful? 2
  • +
  • -

#3 AmericanPi  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 14
  • Joined: 30-July 16

Re: what is the different of @ and : in ruby

Posted 06 August 2016 - 01:30 AM

Are those variable hierarchies(correct my misunderstanding if my grammar suggests it) just for Rails?
@@variable_name (variable is a class)
@variable_name (variable is in a class)
variable_name (is a local variable)..

I use local variables normally so I thought...
or is it just a Ruby on the Rails thing

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1